java - junit5 没有进行测试
问题描述
我有简单的测试
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MyTestClass{
private static final Logger logger = LoggerFactory.getLogger(MyTestClass.class);
private static final Long timeout = 5000L;
@Test
public void test(){
Assertions.assertTrue(true);
}
}
我试图用它运行它mvn test -Dtest=MyTestClass#test test
,但出现错误:
无法在项目 TestProject 上执行目标 org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test):未执行任何测试!(设置 -DfailIfNoTests=false 以忽略此错误。)
当我尝试使用 intellij 运行它时:
发生内部错误。org.junit.platform.commons.JUnitException:ID 为“junit-jupiter”的 TestEngine 未能在 org.junit.platform 的 org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverEngineRoot(EngineDiscoveryOrchestrator.java:111) 中发现测试。 launcher.core.EngineDiscoveryOrchestrator.discover(EngineDiscoveryOrchestrator.java:85) at org.junit.platform.launcher.core.DefaultLauncher.discover(DefaultLauncher.java:92) at org.junit.platform.launcher.core.DefaultLauncher.execute( DefaultLauncher.java:75) 在 com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:71) 在 com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33) 在 com.intellij.rt .junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220) 在 com.intellij.rt.junit.JUnitStarter。
进程以退出代码 -2 结束
我的依赖如下:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<dependencies>
</dependencies>
<configuration>
<trimStackTrace>false</trimStackTrace>
<printSummary>true</printSummary>
<excludes>
<exclude>integration/*.java</exclude>
</excludes>
</configuration>
</plugin>
和
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.11.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>3.11.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.8.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.8.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
为什么 maven 和 intellij 不能执行 Junit5 测试?解决这个问题的方法是什么?surefire 版本应该已经支持 JUnit5 测试。
解决方案
添加<includes>*</includes>
到万无一失的配置。
我有同样的问题,包括所有明确的帮助。我正在使用 surefire 运行此配置3.0.0-M3
。
推荐阅读
- teamcity - 将登录的 teamcity 用户配置为 teamcity 云配置文件中 VM 的所有者
- google-sheets - 谷歌表格到大查询数据大小
- python - Spotify API 刷新网络令牌 - Python
- sql - SQL 查询 - 计算不同的值
- javascript - Vue 3 渲染函数如何设置 v-model 和 onClicks
- flutter - 如何从 carousel_pro 颤振中传输图像的 ID
- java - MSSQL:为什么在我更新实体后 findAll 不起作用 - Spring Boot JPA
- ssh-keygen - ssh-keygen -l -f 文件因 dsa 密钥内容而失败
- javascript - 未捕获的语法错误:无法在模块 Vue 3 PWA Workbox 之外使用导入语句
- android - 为什么我们需要为 DataBinding 和 LiveData 扩展 ```ViewModel()``` 来创建 LiveData 对象