Reputation: 8613
Problem: I'm having a huge code base with a lot of tests. While adding a test I realized that some existing unit tests in there cover the same classes/function twice or more often. Those tests are located in quite different locations, so it's hard to see that they test the same code.
There are no @covers
annotations in this code. So I can't use them for identifying "redundantly tested" code.
PHPUnit can handle a lot of command line flags for an e.g. useless tests with --report-useless-tests
.
It would be great if there would be some --report-redunant-tests
, but as I can see there is no such option.
Question: Do you know how can I find out which code is beeing tested twice and which unit test are responsible for that tests?
Background: In deleting the redundant tests I want to assert the following things.
Upvotes: 2
Views: 429
Reputation: 4025
It's really difficult to detect a "redundant" test. Even if multiple tests pass through the same code, they can test for different scenarios, so all of them are relevant. However I can see how having multiple tests can slow down your process.
My suggestion is to have a look at the coverage-* options. Running a coverage report, for example the HTML one, allows you to browse the code and tells you which lines / classes are covered by each tests. This is meant for manual use, should you wish to automate, look at other types of reports and extract the data you need from them.
However, a good place to start is:
phpunit --coverage-html /tmp/coverage
Good luck!
Upvotes: 2