It seems that this is a quite common issue and I personally stumbled on it at least a couple of times.
Some of the main causes being:
targetTests
: pitest doesn't find tests
assert
keyword: pitest not able to locate junit test
However, today I stumbled upon a new case of 0 tests found, which I struggle to solve. Let us consider this project: https://github.com/bonnyfone/vectalign.
It is a small project and includes one only test class:
src
|
+- main
| |
| ...
|
+- test
|
+- java
|
+- VectAlignTest.java
I added pitest to the pom.xml
:
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.3.2</version>
</plugin>
I run the command mvn clean test org.pitest:pitest-maven:mutationCoverage
.
While the test run just fine, for some reason pitest cannot locate them:
12:23:16 PM PIT >> INFO : MINION : 12:23:16 PM PIT >> INFO : Found 0 tests
...
================================================================================
- Statistics
================================================================================
>> Generated 910 mutations Killed 0 (0%)
>> Ran 0 tests (0 tests per mutation)
You can find the complete pom.xml
here: https://pastebin.com/F28ZpcMk
And here is the complete output for mvn clean test org.pitest:pitest-maven:mutationCoverage
: https://pastebin.com/tWHgq43a
Now my question is, what is going wrong in this particular case? How does pitest determine which are the test classes?
Your help would be much appreciated :)
No. It is a convention to start with one test class per class under test, but it is not necessary. Test classes only provide a way to organize tests, nothing more.
Pitest inserts mutants into a jvm by re-writing the class after it has loaded. This is orders of magnitude faster than starting a new jvm or creating a new classloader, but code in static initializer blocks is not re-run so the mutants have no effect.
gradle-pitest-plugin can be used in multi-module projects. The gradle-pitest-plugin dependency should be added to the buildscript configuration in the root project while the plugin has to be applied in all subprojects which should be processed with PIT.
PITest did not find my classes or test classes because I did not have them in a package. Once I put them in a package, everything worked great. I suspect that you could also specify the class and test class locations manually.
To quote that answer at the (now deleted) linked question:
I just spent a great deal of time with the same message
No mutations found. This probably means there is an issue with either the supplied classpath or filters.
My problem was simple: I had created a couple of test projects in IntelliJ using Maven. But I did not have a package. I was using the default package and PITest was failing every time. The PITest has a plugin that might work with just the default package if you specify the class and test classes. But all the documentation said that it should work by default. A verbose output even showed that PITest was finding the correct project folders, but it still didn't work. Henry Cole was even good enough (the developer of PITest) to look at my POM.xml file and confirm that it looked good.
In summary, PITest works great if you put your Java code in a package.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With