-
Notifications
You must be signed in to change notification settings - Fork 385
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
Get coverage per test #973
Comments
I tried going through the code, but it's a bit too hard to figure out how to debug it properly. Is there a way to debug the tests in the project somehow? |
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? |
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 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 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. |
You could do this by scripting your test runs. |
@petli if I modified And would that work for per-test coverage technically? |
I don't know much about the collector architecture, but it's a good point to investigate that. May not need any of the call stack analysis or hit array per test, if the array can be fetched and reset between each test instead. That requires that tests are not run in parallel, but that should be a reasonable restriction. |
Yeah, that's a reasonable restriction for me. I'm building a tool that can run only affected tests in dotnet, from looking at your GIT changed files. |
Is it possible to reset between each test right now? Or is that something I should add? I'd love to contribute on this. |
@ffMathy can you elaborate better your scenario? Collectors could a way and I agree with @petli on the complexity related to redesign current implementation to support this, also we should try to avoid inprocess collectors if possible to avoid the needs of too much config for injection(not so user friendly with runsettings), at the moment in process collectors is embedded inside vstest platform and we're planning to move out to cleanup code the code base. Another possibility could be expose engine standalone to inject and control hits manually to get an "in memory" report for every test using standard test features i.e. for xunit |
I want to build a CLI that internally runs tests for you serially (non-parallel) that have been affected by your GIT changes, based on previous coverage. That's why I want to be able to see what tests ran through a specific line of code. See the examples given in my other issue here: dotnet/aspnetcore#25194 |
@MarcoRossignoli what do you think about what @petli said here:
Can you point me in the right direction of implementing such reset functionality, or perhaps how to do it? As I mentioned earlier, I am running all tests serially one at a time, so there is no parallelism. |
If I understood well your tool idea is:
If you want to use coverlet this could be implemented with collectors, specifically with in-process one because it provides TestStart/TestEnd event. The workflow of coverlet coverage is:
The problem now it that you should access at the end of every test to every instrumented dlls like https://github.com/coverlet-coverage/coverlet/blob/master/src/coverlet.collector/InProcDataCollection/CoverletInProcDataCollector.cs#L54 and save/persist current hits array(where there is current test hits) somewhere with the test name and reset hits array(https://github.com/coverlet-coverage/coverlet/blob/master/src/coverlet.core/Instrumentation/ModuleTrackerTemplate.cs#L22). When all tests ends the control come back to out of process collector https://github.com/coverlet-coverage/coverlet/blob/master/src/coverlet.collector/DataCollection/CoverletCoverageCollector.cs#L158 where you have to create n number of reports for every test. After that your tool could do a diff comparing test/lines with git changes. As you can see this is no a simple change, also it's very specific and limited to what you needs and the issue with parallel execution is not negligible for big project(today we have already some issue with big repo related to the invasive nature for instance coverage in repo like Roslyn is very very very slow). I mean the idea of generalize/expose internal coverage engine could help because adding some features(for instance call a callback for every hit, have access to prepared structure in memory etc...) and with brand new collectors used only for your needs(run selected test, totally unrelated to "coverage" problem, you're using coverage only to have a way to know who touch what lines) you could evolve with no "blockers" or dependence of coverlet engine(related only to code coverage and report generation). If we expose core standalone we have only to create the correct contracts(interfaces) but when will be stable won't need great updates(implementation is hidden). BTW your idea is very cute! If you want discuss further we can setup a call and I can explain better coverlet architecture at the moment there is no documentation and it's a bit complex explain in a post like this and also answer quickly. |
cc: @tonerdo |
@MarcoRossignoli thank you for that elaborate explanation! However, I still do have some questions. When would be a good time for a call? I think that's a great idea! My timezone is UTC+1 though. Also, how do we make the call? Skype? Discord? Whereby? Zoom? |
If we expose this, then I can finish coverlet-coverage#973, where I have referenced the project, and want to reset the hits array.
I found a way to get it working I think - I'll have a PR ready soon. |
DM on twitter we'll arrange a call on skype https://twitter.com/MarcoRossignoli |
Is there any progress on this? Are there any plans to put it on roadmap? |
There's no plan to support this one for the moment, the volume of work to support this one is not trivial. |
What if I would like to contribute, to let's say implement it in a sequential way? Could you assist with code review and pull request approval when it's done? |
This issue is stale because it has been open for 3 months with no activity. |
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.
The text was updated successfully, but these errors were encountered: