【发布时间】: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