mvn test运行Junit5测试用例时检测不到测试类的问题
问题再现:
使用 Intellij Idea 开发工具,每次执行单个 Junit5 测试时一切正常。
但是在项目目录中,执行 mvn test,或者 Intellij 右边的 Maven 打开后执行 Lifecycle 的 test 时,出现问题:

查阅文档
Junit5-User Guide-Get Started 给出了一些 Junit5 的例子。
其中,junit5-jupiter-starter-maven pom.xml 中给了我一些提示!
修改 pom.xml
- 依赖 junit-jupiter-engine
- 新增插件 maven-surefire-plugin
<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>org.coderead</groupId>
    <artifactId>test-junit5</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>${maven.compiler.source}</maven.compiler.target>
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.7.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.2</version>
            </plugin>
        </plugins>
    </build>
</project>

 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号