【问题标题】:No tests found with test runner JUnit5没有使用测试运行器 JUnit5 找到测试
【发布时间】:2019-11-01 02:04:29
【问题描述】:

我刚刚开始学习 Junit 并创建了一个非常简单的测试类,但我遇到了两个问题 i)不能直接作为 JUnit 测试运行。(我必须为我尝试在 eclipse idk 中运行的每个 java 文件运行配置,为什么会这样) ii)我针对同一个问题遵循了几个答案,但没有任何帮助——没有使用测试运行程序 JUnit 5 找到测试

我尝试了以下解决方案 添加依赖项, 重新启动, 类似帖子中提供的其他解决方案

package io.javatest;

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Test;

class MathUtilsTest {

    @Test
    void test() {
        System.out.println("This test ran");
    }

}

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>io.javatest</groupId>
  <artifactId>junit-5-basics</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>junit-5</name>

  <properties>
        <maven.compiler.target>11</maven.compiler.target>
        <maven.compiler.source>11</maven.compiler.source>
        <junit.jupiter.version>5.4.0</junit.jupiter.version>
        <junit-platform.version>1.2.0</junit-platform.version>
  </properties>

    <dependencies>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit.jupiter.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>${junit.jupiter.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
         <groupId>org.junit.platform</groupId>
         <artifactId>junit-platform-launcher</artifactId>
         <version>1.1.0</version> 
         <scope>test</scope> 
        </dependency>`enter code here`
    </dependencies>
</project>

【问题讨论】:

    标签: spring maven junit pom.xml


    【解决方案1】:

    这是一个使用 maven 和示例测试的工作示例 junit 5 项目。测试在命令行使用“mvn test”运行。

    https://github.com/cameronhurd/junit5-example

    【讨论】:

      【解决方案2】:

      在您的 IDE 中,右键单击 junit 测试用例并选择“运行方式”并单击“运行配置”,选择配置并向下滚动并将“测试运行器”更改为 junit 4。现在应用并关闭并运行.这为我解决了问题。但想知道根本原因。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-08-25
        • 1970-01-01
        • 2018-05-29
        • 2018-06-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多