Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to determine code coverage without running the code?

I am not asking the static code analysis which is provided by StyleCop or Fxcop. Both are having different purpose and it serves well. I am asking whether is there a way to find the code coverage of your user control or sub module? For ex, you have an application which uses the helper classes in a separate assembly. Inorder to ensure the unit testing code coverage, we need to run the application and ensure using NCover or similar tool.

My requirement is, without running it, is there any possible to find code coverage of the helper classes or similar kind of assemblies?

like image 972
sankar Avatar asked Dec 22 '22 05:12

sankar


2 Answers

See Static Estimation for Test Coverage for a technique that estimates coverage without executing the source code.

The basic idea is to compute a program slice for each test case, and then "count" what the slice enumerates. A (forward) slice is effectively that part of a program that you can reach from a specific starting point in the code, in this case, the test code.

While the technical paper above is hard to get if you're not an ACM member [or you didn't attend the conference where it was presented :], there's a slide presentation here.

Of course, running this static estimator only tells you (roughly) what code will be exercised. It doesn't substitute for actually running the tests, and verifying that they pass!

like image 176
Ira Baxter Avatar answered Jan 04 '23 11:01

Ira Baxter


In general, the answer is no. This is equivalent to the halting problem, which is not computable.

like image 45
Simon Nickerson Avatar answered Jan 04 '23 12:01

Simon Nickerson