【发布时间】:2021-03-15 02:47:51
【问题描述】:
我是第一次编写单元测试。为了在 IntelliJ 中创建测试文件,我使用快捷方式 [https://www.jetbrains.com/help/idea/create-tests.html] 创建了一个*Test.java。现在,当我尝试运行 mvn test 时,它没有运行任何测试。
pom.xml
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
- SO 我发现很少有答案是检查名称。我查了一下,文件名是
<classNametoTest>Test.java,还可以看到文件上的JUnit符号。 - 我有另一个名为
test的文件夹(在根目录中)。为了验证,我尝试重命名文件夹并做了mvn clean package->mvn test。不运行测试。 -
Test文件夹也在src中 [https://stackoverflow.com/questions/6178583/maven-does-not-find-junit-tests-to-run]
【问题讨论】:
-
你配置了surefire插件吗? maven.apache.org/surefire/maven-surefire-plugin/examples/…
-
请添加完整的 pom 文件...
-
我从 org.junit.jupiter.api.Test 导入了@test,现在它可以工作了。谢谢!
标签: java maven unit-testing junit