问题
I want to know the tests that cover a particular method. However, NCover does not provide this information. I dont want to use VSTS as my code is not in TFS. Is there any way/tool to do that in .NET?
回答1:
Fundamentally what you have to do is to run your test coverage tool once for each test, producing a coverage vector for that test. If you have hundreds of tests, you can collect coverage for each test separately.
Then if coverage vector N covers a method, test N caused that coverage.
I don't know if NCover if/how NCover can cross reference back to the range of lines that correspond to the source code of the method.
For our C# Test Coverage Tool, the instrumenter tool produces line number ranges for each coverage test point, and there is a test point inserted at the start of every method. So if you know the line number of a method in a file, you can technically locate the entry coverage point, thus the line range that makes up the method, thus all test coverage points in the method. With such a list it is straightforward to compute whether a test coverage vector has hit those points. So, our tool has the information necessary to provide this data, although it isn't well documented. You could ask us for further documentation or help doing this.
回答2:
dotCover I believe provides that sort of support in the UI but I am not so sure if this information is available from a build machine.
OpenCover has work in progress on one of its forks - This is one of the original aims of the project and has driven the design of OpenCover to reach this aim with a single run of the tests - stay tuned...
Finally as Ira mentions you can run a test individually and get coverage (using most coverage tools such as NCover, PartCover, OpenCover, ...) from a single test executed with NUnit/MSTest (insert test tool of choice) however you will also get coverage of anything that happened in any setup/teardown actions as well.
来源:https://stackoverflow.com/questions/8416412/net-determining-which-test-cases-covered-a-method