Home > Mobile >  Maven not running JUnit test
Maven not running JUnit test

Time:11-02

My pom.xml

<dependency>
  <groupId>org.junit.jupiter</groupId>
  <artifactId>junit-jupiter</artifactId>
  <version>5.8.1</version>
  <scope>test</scope>
</dependency>
...
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>3.0.0-M5</version>
</plugin>

But when I do mvn clean test

-------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

Note that IntelliJ does recognize the test enter image description here (Although when I click the test folder and select Run All Tests, it says No tests found)

Why is Maven not running my unit tests and how do I fix it?

CodePudding user response:

If you're using JUnit 5 (Jupiter), you need to import org.junit.jupiter.api.Test instead of org.junit.Test (the latter is for JUnit 4).

  • Related