Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easier code coverage collection for C# contract tests #38

Open
majordutch opened this issue Jul 15, 2022 · 1 comment
Open

Easier code coverage collection for C# contract tests #38

majordutch opened this issue Jul 15, 2022 · 1 comment

Comments

@majordutch
Copy link

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.
@devhawk
Copy link
Contributor

devhawk commented Nov 14, 2022

This requires a Data Collector (https://github.com/Microsoft/vstest-docs/blob/main/docs/analyze.md).

@devhawk devhawk self-assigned this Nov 15, 2022
@devhawk devhawk removed their assignment Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants