我的测试已编译并“运行”,但我的测试方法未执行。 Maven 打印:
T E S T S
-------------------------------------------------------
Running spring.test.Aufgabe0.TestMinimalTestCase
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@4b
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.408 sec
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
我的测试类非常小,应该会失败:
package spring.test.Aufgabe0;
import org.junit.Test;
import static org.junit.Assert.*;
public class TestMinimalTestCase {
@Test
public void testMinimalTest() {
int i = 3;
assertTrue(i == 2);
}
}
我导入了 JUnit 并配置了测试路径,如您所见:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
...
<build>
<sourceDirectory>src/java</sourceDirectory>
<testSourceDirectory>src/test</testSourceDirectory>
测试套件在 Eclipse 中运行,但我不明白为什么它不能与 Maven 一起使用。
解决方案:
导入testng测试。这应该没有什么区别:“测试源目录中的测试可以是以下内容的任意组合:TestNG JUnit(3.8 或 4.x)...”Surefire documentation
如何在我的范围/依赖列表中使用 testng 运行 junit 测试?
最佳答案
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@4b
看看这个,我想您在 Maven 构建时使用 TestNG,但您导入了 org.junit.Test
。
使用@Test
来自 TestNG。
关于java - Maven:测试用例已运行,但未调用测试方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19595710/