Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tools for "inverse" code coverage?

I'm familiar with a number of code coverage tools, which tells me what percentage of lines / branches / etc are covered by my tests, and even show me which parts of the code have poor coverage.

Are there any tools which do the opposite -- that is, given a section of code, can it show me which tests touch it? That would make it easy to start exploring unfamiliar & poorly documented code, by playing with the tests that are relevant.

You might say it should be obvious from the way the unit tests are organized, but the fact is it often is not. I've worked with more than one project where this was the case.

I happen to be interested in java / scala, but I'm also just interested if anything does this or its just a totally crazy idea.

like image 768
Imran Rashid Avatar asked Nov 08 '22 18:11

Imran Rashid


1 Answers

The code coverage tool in the JMockit toolkit (which I develop) provides this feature. You can see it at work in the sample coverage report that is available online.

For line 72 in the OrderRepository.java source file, for example, the report page shows that two tests touch it: OrderFindersTest#findOrderByCustomer and OrderFindersTest#findOrderByNumber.

like image 97
Rogério Avatar answered Jan 03 '23 10:01

Rogério