.NET-确定哪些测试用例涵盖了一个方法-.NET-determiningwhichtestcasescoveredamethod
作者:我不是咸鱼仔 | 来源:互联网 | 2023-09-23 12:26
Iwanttoknowtheteststhatcoveraparticularmethod.However,NCoverdoesnotprovidethisinfor
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?
我想知道涵盖特定方法的测试。但是,NCover不提供此信息。我不想使用VSTS,因为我的代码不在TFS中。在.NET中有没有办法/工具呢?
2 个解决方案
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.
然后,如果覆盖矢量N覆盖方法,则测试N导致该覆盖。
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.
我不知道NCover是否/如何将NCover交叉引用回到与方法源代码对应的行的范围。
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.
对于我们的C#测试覆盖率工具,仪器工具为每个覆盖测试点生成行号范围,并在每个方法的开头插入一个测试点。因此,如果您知道文件中方法的行号,则可以在技术上定位条目覆盖点,从而定义构成方法的行范围,从而确定方法中的所有测试覆盖点。使用这样的列表,可以直接计算测试覆盖率向量是否已经达到这些点。因此,我们的工具具有提供此数据所需的信息,尽管没有详细记录。您可以向我们索取进一步的文档或帮助您做到这一点。