question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get coverage per test

See original GitHub issue

Using coverlet.core, is it possible to get a “parent line” for a specific hit, to determine the call stack of the covered line?

I want to use that to figure out which tests ran through a specific line.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:19

github_iconTop GitHub Comments

2reactions
petlicommented, Oct 23, 2020

I’ve been curious about getting per-test coverage reports since the file formats tend to support it, but it would require a fair bit of redesign of the hit collection and a challenge to do it efficiently. Right now there is a single int[] per module that the hits are recorded into.

My rough idea of what’s necessary to do to create this is that you have to change how methods are instrumented so that on entry they locate the unit test (if any). This would be done by traversing the callstack up, and then cache the result in an AsyncLocal so it doesn’t have to be done by every nested instrumented method. A hit array is created for each unit test, and used in the instrumented code instead of the static array that’s currently injected.

When the test is done all these hit arrays would have to be transferred over to the coverlet process. This is already a time critical operation that is only stable when using the vstest collector driver, so moving potentially thousands of hit arrays would only be feasible in that driver, excluding the standalone and msbuild drivers as it stands now.

Finally the coverlet core will need to collate these hit arrays to get per-test statistics.

1reaction
petlicommented, Oct 23, 2020

If it’s not possible to figure out which tests ran through a specific line, could it perhaps be possible to generate a coverage file per test in the test run?

You could do this by scripting your test runs. dotnet test -t lists the tests in a project and iterate over them in a script, and then your script can run test by test by running dotnet test --filter "$testname" --other-parameters-as-needed-to-get-coverage. This will not be very efficient, of course.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get coverage per test in SonarQube? - java
I'm having difficulties to set up my project in a way so SonarQube reports test coverage per test. During the analysis with Sonar...
Read more >
Test Coverage Tutorial: Comprehensive Guide With Best ...
To calculate coverage of your tests, divide the total number of lines in a software application by the number of lines covered by...
Read more >
Test coverage overview - SonarQube Docs
Test coverage reports tell you what percentage of your code is covered by your test cases. Test execution reports tell you which tests...
Read more >
Run with coverage - IntelliJ IDEA
To collect code coverage statistics for tests, select the Enable coverage in test folders checkbox.
Read more >
Obtaining Coverage per Test Case. - CQSE GmbH
This thesis presents an algorithm for selecting and prioritizing test cases for Java applications based on a set of changes that have been...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found