问题
I've got a new Java project open in IntelliJ with Maven as its build tool, with one class and one JUnit 5 test class at the moment. When I direct IntelliJ to run tests, individually or all together, it works. But when I go to the terminal and hit mvn clean test
or do the same from the Maven pane within IntelliJ, it skips over the tests.
Unlike the questioner with this similar question, however, I'm not getting any error message. The test class is found and does compile. I do not have the same problem (incorrect file naming) that he had.
EDIT: Stackoverflow asks me why this isn't a duplicate of this question. It is the same problem, but their solution (from 2016) is no longer correct. You don't need to add the "provider" dependency anymore.
Here's the relevant section of my Maven output:
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ markovmodels ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\Users\joe\foo\markovmodels\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ markovmodels ---
[INFO] Surefire report directory: C:\Users\joe\foo\markovmodels\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.648 s
[INFO] Finished at: 2019-08-13T09:02:53-04:00
[INFO] ------------------------------------------------------------------------
I don't know if it's a useful clue, but I observed that the target/surefire-reports
directory was not created.
In the pom.xml
I have these two test-related dependencies:
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.4.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.4.2</version>
<scope>test</scope>
</dependency>
They are directly copied over from another project which works. I have not specified a version of the Surefire plugin or changed any of its defaults, so the effective POM is the same as my other projects (it uses maven-surefire-plugin
version 2.12.4). The test source file seems to be in the right directory and have the right naming convention. What mistake could I be making?
The code at its current state can be here on Github.
回答1:
It was an issue with the maven-surefire-plugin
There was something wrong with the default version of the maven-surefire-plugin
, and I was able to fix it by upgrading that. I solved the problem by copying relevant sections from the JUnit5 sample Maven project on Github:
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.5.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
来源:https://stackoverflow.com/questions/57478539/maven-silently-fails-to-find-junit-tests-to-run