[英]Maven won't run JUnit5 tests
(顺便说一句:是的,我在我的 pom 中包含了 Maven surefire 插件。)
我无法说服 Maven 运行我的 JUnit5 测试。
我在下面包括了我的 pom 的内容。 谁能告诉我我做错了什么? 谢谢您的帮助。
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>uw.syp.java</groupId>
<artifactId>Temp1</artifactId>
<packaging>jar</packaging>
<version>01</version>
<name>Temp1</name>
<url>http://maven.apache.org</url>
<properties>
<developer>JesseJW</developer>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.3.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArgs>
<arg>-Xlint:all</arg>
<arg>-Xlint:-serial</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
</project>
根据要求:源代码,包括导入:package app;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import java.net.URL;
import javax.swing.JOptionPane;
class AppTest
{
void test()
{
System.out.println( "*************" );
URL resURL = getClass().getClassLoader().getResource( "ResFile.txt" );
System.out.println( resURL );
assertNotNull( resURL );
if ( resURL != null )
{
System.out.println( resURL.getPath() );
}
}
}
也许您的代码导入了错误的Test
注释; org.junit.Test
, org.testng.annotations.Test
, ...
org.junit.jupiter.api.Test
应该被导入。
package app;
import static org.junit.jupiter.api.Assertions.fail;
import org.junit.jupiter.api.Test;
public class AppTest {
@Test
void test() {
fail("Not yet implemented");
}
}
您似乎错过了测试方法上的注释。 只需将您的代码调整为:
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import java.net.URL;
import javax.swing.JOptionPane;
class AppTest
{
@Test
void test()
{
System.out.println( "*************" );
URL resURL = getClass().getClassLoader().getResource( "ResFile.txt" );
System.out.println( resURL );
assertNotNull( resURL );
if ( resURL != null )
{
System.out.println( resURL.getPath() );
}
}
}
Surefire 插件(自 2.2 起)使用的参数,考虑到项目目录结构,值得仔细检查:
testSourceDirectory:包含测试 class 源的测试源目录。 默认值为:${project.build.testSourceDirectory}(默认值:src/test/java)。
classesDirectory(用于生成的正在测试的类)。 默认值为:${project.build.outputDirectory}(默认:target/classes 文件夹)。
要更改 pom.xml 中的默认值:
<build>
<testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
->
<build>
<testSourceDirectory>${project.basedir}/myPath</testSourceDirectory>
http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.