首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未找到使用测试运行器JUnit5的测试

未找到使用测试运行器JUnit5的测试
EN

Stack Overflow用户
提问于 2019-06-18 20:13:41
回答 2查看 1K关注 0票数 1

我刚刚开始学习Junit,并创建了一个非常简单的测试类,但是我遇到了两个问题:1)不能直接作为JUnit测试运行(我必须为我尝试在eclipse idk中运行的每个JUnit文件运行配置,这是为什么) ii)我跟踪了同一问题的几个答案,但没有帮助--使用测试运行器JUnit 5找不到测试。

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

代码语言:javascript
复制
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>
EN

回答 2

Stack Overflow用户

发布于 2019-06-20 00:09:51

这是一个使用maven的junit 5项目的工作示例,并进行了示例测试。在命令行中使用"mvn test“运行测试。

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

票数 0
EN

Stack Overflow用户

发布于 2021-02-20 06:37:58

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56648914

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档