简体   繁体   中英

When pitest cannot find the test classes

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:

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 :)

I just added a solution at this link:

https://stackoverflow.com/questions/34945420/pitest-not-running-correctly

To summarize, 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.

I am facing quite the same issue. For me specifying the exact test packages helped. In your case maybe you could add:

<configuration>
    <targetTests>
      <param>VectAlignTest*</param>
    </targetTests>
</configuration>

But of course, this is quite a dirty workaround. Maybe somebody knows the root cause of the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM