Skip to content

Easier code coverage collection for C# contract tests #38

@majordutch

Description

@majordutch

A helpful feature for C# contract tests would be an easier way to collect code coverage for the original contract source from the neo-test execution.

@devhawk provided some insightful information regarding this:

TestApplicationEngine automatically collects coverage information while 
executing. You can retrieve it via the GetHitMap and GetBranchMap methods

The Get*Map methods take a contract hash parameter - coverage information 
is tracked separately per contract

The hit map is a dictionary mapping NeoVM addresses to a hit count (i.e. 
how many times that specific instruction was executed)

the branch map is a dictionary mapping NeoVM addresses of branch instructions 
to a pair of hit counts - how many times this instruction branched vs continued

So that's the good news. Bad news is that there is no built-in mechanism to 
aggregate the info or publish it in a format that existing code coverage tools 
can use

There's also a need to map NeoVM address to source code lines. I assume folks 
are more interested in a source level view of coverage rather than an assembly 
level view

There is code in the test runner project (part of the neo test repo, a tool to 
enable non-c# developers to run tests) that iterates sequence points from debug 
info to retrieve hit/branch coverage info, but it's not in an easy-to-reuse 
method, it's just part of WriteResultsAsync method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions