I'm trying to introduce Unit tests to our system, and have run into a problem with Junit not finding test. I have these 3 tests:
When I run all tests in the module:
It finds X and Y tests, but not Z:
The difference between the 3 is only in the package name:
- The package
com.exlibris.x
(XTest) doesn't exist in the project - The package
com.exlibris.core.infra.svc.api.flags
(YTest) exists in a different module in the project (that is outputted to a different jar file) - The package
com.exlibris.repository.web.mms.publishing
(ZTest) exists in the same module under the src/main/java
My pom.xml has the following dependencies (inherited from the parent pom):
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.9.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.9.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-engine</artifactId>
<version>1.9.1</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
EDIT: These are my run configurations
CodePudding user response:
So it turned out there were a few issues (some of them are likely not related to the specific question, but still best practices). What helped for me was:
- Consolidate dependency management of JUnit by importing junit-bom
- Upgrading maven-surefire-plugin to latest version
- Removing unnecessary configs from maven-surefire-plugin (my configuration tag is now empty)
- Reloading the project in IntelliJ (Right click project -> Maven -> Reload project)
Thanks a lot to khmarbaise and Kathrin Geilmann for the help :)