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?
2 Answers
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.

- 93,541
- 22
- 172
- 341
-
Downvoter: what part of this answer does not address OP's question? It describes exactly what is needed, so OP Knows what to look for, and help in case he can't find it. Sheesh. – Ira Baxter Dec 08 '11 at 02:28
-
Yes, I do. People dump a lot of hate on me for providing solutions to problems, that aren't free. (For many of the solutions I provide, there aren't any free alternatives, so I conclude the haters don't want answers at any price). Its amazing... I suspect most of them are providing their employer solutions for money and they don't seem to object to themselves. – Ira Baxter Dec 08 '11 at 02:43
-
Off topic: Odd isn't it, even though I do an open source product version that sorts of occupy that space I will quite happily mention paid alternatives. In then end I do my product so that open source projects can have some free tooling and so that the knowledge is not lost to the open source community. – Shaun Wilde Dec 08 '11 at 21:24
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.

- 8,228
- 4
- 36
- 56
-
You need more than just the test coverage vector. You need somehow to identify that the body of the method is covered by a vector, by means (presumably) other than visual inspection of the coverage data. – Ira Baxter Dec 08 '11 at 02:30
-
Ira - I assume that was what you alluded to, NCover et al all have some sort of visualization of coverage to code that could be used to visualize coverage for a 'single' test. Aggregating this into a single viewer is 'currently' an exercise for the reader. – Shaun Wilde Dec 08 '11 at 02:38
-
OP is asking for a method, which tests cover it. Presumably he has a (fully qualified) method name, and wants to call a function that gives back a list of integer test numbers. Looking at a set of pixels won't answer that question. – Ira Baxter Dec 08 '11 at 02:42
-
The visualization via a viewer doesn't have to be a set of pixels. XYZCover reports visit counts to a sequence point and so it would be possible to find all points where the visit count is greater than 0 and then turn this into a report. A sequence point should be able to identify a method and the line of code associated with the sequence point. It is still an exercise for the reader but requires some data mining however most people IME only really want this sort of report when in Visual Studio. dotCover can visualize a test and it's own coverage and so may also do the inverse – Shaun Wilde Dec 08 '11 at 21:19