我有一个 Spring Boot 项目。我已经在 .../src/test/java/... 目录中编写了单元测试。我所有的单元测试都是 *Test.java 形式。当我运行“mvn test”时,我得到以下输出:
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ frm-api ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 6 source files to /Users/JoelRives/Projects/fasor/fasor-service/fatality-review/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.22.0:test (default-test) @ frm-api ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
显然,maven 在编译单元测试时会看到它们。但是,如您所见,它不会运行它们。
我的 pom 中有以下相关的 Maven 依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<version>1.5.3.RELEASE</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
<version>1.4.194</version>
</dependency>
我的 pom 还包含以下插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.3.0-M1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.2.0-M1</version>
</dependency>
</dependencies>
</plugin>
非常感谢任何有关此问题的帮助。
我没有显示我的整个 POM。这是 Junit 的内容:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<version>1.5.3.RELEASE</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
<version>1.4.194</version>
</dependency>
最佳答案
看起来如果您使用 Junit4 和 Surefire 插件版本 2.22 及更高版本,则测试不会被接受。我遇到了类似的问题,使用 Surefire V2.21.0 似乎有效。
下面是我的确定配置
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
</plugin>
关于java - Spring Boot Maven 单元测试未执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51270218/