What constitutes full code coverage when I invoke

2019-08-09 04:57发布

问题:

What is considered 100% when I invoke dotCover from an MSTest build step in TeamCity? Is 100% all of the compiled code? Is it all the code for all the assemblies which the tests have touched? Is it all the classes which the tests have touched?

When I invoke dotCover from a TeamCity MSTest build step which runs My.Tests.dll, which lines are code are being tracked?

回答1:

dotCover only provides reporting on statement-level coverage, where as other tools like NCover also include function and branch coverage.

With a TeamCity MSTest build step you get to specify which assemblies you want the coverage reported for in the "Filters" field. This allows you to just specify an exclude for a .Tests pattern or just include one assembly. See the TeamCity documentation for more details: http://confluence.jetbrains.net/display/TCD7/JetBrains+dotCover

I believe that if you don't specify any filters, all code in all assemblies that were loaded into the CLR are included (you have to cause an assembly load from the code you call, so some assemblies might not be included, this is just the lazily loading of the CLR). This is because tools like dotCover use the CLR profiling API and do not instrument your code upfront. Note that dotCover will exclude assemblies from the GAC.



回答2:

Not sure if I fully understood your question but will take a shot anyways. As I understand 100% coverage means that every line of code in the project is exercised by your test cases. Basically that means that you have ensured that control flows thru every line of code in your project.

In general I have never seen 100% coverage as its very difficult to test every code path. Consider for example different types of exceptions that are handled by your code, how do you exercise the catch block for each exception by some test case? You would need to simulate an exception somehow, which is not always easy.