java - Maven:测试用例已运行,但未调用测试方法

标签 java maven junit maven-3 junit4

我的测试已编译并“运行”,但我的测试方法未执行。 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/

相关文章:

Spring Boot War 部署到 Tomcat

java - 我如何在 Xvfb 上启动 mvn 测试阶段?

java - 在 Eclipse 中找不到 KeyPairGenerator

java - Netty 的长度前缀框架 - 无法设置 LengthFieldPrepender/Decoder

java - Android Studio 中未生成 MainActivityBinding 文件

java - maven的REST服务下获取JDBC连接

java - testNG 没有可运行的方法

java - 模拟静态方法时出现内容类型错误

Java 查找和替换字符串的最佳方式?

java - Android SMS BroadcastReceiver NullPointer