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

I am not asking for the static code analysis provided by StyleCop or Fxcop. Both have different goals, and they serve well. I ask, is there a way to find the code coverage of your user control or module? For example, you have an application that uses helper classes in a separate assembly. In order to provide coverage for the module testing code, we need to run the application and ensure that we use NCover or a similar tool.

My requirement, without running it, is it possible to find code coverage of auxiliary classes or similar assemblies?

+4
source share
5 answers

I would say no; except for the "dead code" that the compiler can detect.

My definition of code coverage is a result that indicates how many times each line of code runs in your program: which, of course, means starting the program. The determining factor here is, as a rule, the values โ€‹โ€‹of the data passing through the program, which determine the execution paths executed by the symbols. Static analysis, like the compiler, can output lines of code that cannot be executed under any conditions.

An example here is that your program uses a third-party library, but there is an error in the library. If your program never uses those parts of the library, or the data that you send to the library makes it avoid errors, then you will not be affected.

You can write a program that, by reflection, assumes that all conventions are accepted, and follows all function calls through all derived classes, but I'm not sure what this will tell you. This, of course, cannot tell you if there are errors in the lines of code.

0
source

See Static Evaluation for test coverage for a method that evaluates coverage without executing source code.

The basic idea is to compute a piece of the program for each test case, and then โ€œcountโ€ what the slice lists. A (direct) slice is actually that part of the program that you can reach from a specific starting point in the code, in this case, the test code.

While the technical article above is hard to get if you are not a member of ACM [or you did not attend the conference where it was presented:], there is a slide presentation here .

Of course, starting this static evaluation only tells you (approximately) which code will be implemented. This does not replace the actual execution of tests and verification of their passage!

+5
source

In general, the answer is no. This is equivalent to a stop problem that is not computable.

+3
source

There are (research) tools based on abstract interpretation or model validation, which can display coverage properties without execution, for subsets of the language. See, for example,

"Analysis of functional coverage in validating a limited model," Gross, D. Kuhne, W. Drechsler, R. 2008

In general, yes, there are approaches, but they are specialized and may require some formal methods. This material is still the most advanced research.

+2
source

Coverity Static Analysis is a tool that can identify many secret flaws in a program. It can also identify dead code and can be used to help meet test rules such as D0178B, which requires developers to demonstrate that all code can be executed.

0
source

Source: https://habr.com/ru/post/1302407/


All Articles