Maven没有找到要运行的JUnit测试

Zug*_*alt 387 java junit junit4 maven-3 maven

我有一个maven程序,它编译得很好.当我运行mvn test它时不会运行任何测试(在TESTs标题下说There are no tests to run.).

我用一个超级简单的设置重新创建了这个问题,我将在下面包含以及运行时的输出-X.

单元测试从eclipse运行良好(两者都使用默认的junit包,当我改为包含maven下载的junit.jar时).mvn也test-compile正确地在test-classes下创建了类.我在OSX 10.6.7上使用Maven 3.0.2和java 1.6.0_24运行它.

这是目录结构:

/my_program/pom.xml
/my_program/src/main/java/ClassUnderTest.java
/my_program/src/test/java/ClassUnderTestTests.java
Run Code Online (Sandbox Code Playgroud)

pom.xml中:

<?xml version="1.0" encoding="UTF-8"?>
<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>my_group</groupId>
    <artifactId>my_program</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>My Program</name>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
Run Code Online (Sandbox Code Playgroud)

ClassUnderTest.java:

public class ClassUnderTest {

    public int functionUnderTest(int n) {
        return n;
    }

}
Run Code Online (Sandbox Code Playgroud)

ClassUnderTestTests.java:

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class ClassUnderTestTests {

    private ClassUnderTest o;

    @Before
    public void setUp() {
        o = new ClassUnderTest();
    }

    @Test
    public void testFunctionUnderTest_testCase1() {
        Assert.assertEquals(1, o.functionUnderTest(1));
    }

    @Test
    public void testFunctionUnderTest_testCase2() {
        Assert.assertEquals(2, o.functionUnderTest(2));
    }
}
Run Code Online (Sandbox Code Playgroud)

mvn -X测试结束:

[DEBUG] Configuring mojo org.apache.maven.plugins:maven-surefire-plugin:2.7.1:test from plugin realm ClassRealm[plugin>org.apache.maven.plugins:maven-surefire-plugin:2.7.1, parent: sun.misc.Launcher$AppClassLoader@5224ee]
[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-surefire-plugin:2.7.1:test' with basic configurator -->
[DEBUG]   (s) basedir = /Users/aaron/Programs/my_program
[DEBUG]   (s) childDelegation = false
[DEBUG]   (s) classesDirectory = /Users/aaron/Programs/my_program/target/classes
[DEBUG]   (s) disableXmlReport = false
[DEBUG]   (s) enableAssertions = true
[DEBUG]   (s) forkMode = once
[DEBUG]   (s) junitArtifactName = junit:junit
[DEBUG]   (s) localRepository =        id: local
      url: file:///Users/aaron/.m2/repository/
   layout: none

[DEBUG]   (f) parallelMavenExecution = false
[DEBUG]   (s) pluginArtifactMap = {org.apache.maven.plugins:maven-surefire-plugin=org.apache.maven.plugins:maven-surefire-plugin:maven-plugin:2.7.1:, org.apache.maven.surefire:surefire-booter=org.apache.maven.surefire:surefire-booter:jar:2.7.1:compile, org.apache.maven.surefire:surefire-api=org.apache.maven.surefire:surefire-api:jar:2.7.1:compile, org.apache.maven.surefire:maven-surefire-common=org.apache.maven.surefire:maven-surefire-common:jar:2.7.1:compile, org.apache.maven.shared:maven-common-artifact-filters=org.apache.maven.shared:maven-common-artifact-filters:jar:1.3:compile, org.codehaus.plexus:plexus-utils=org.codehaus.plexus:plexus-utils:jar:2.0.5:compile, junit:junit=junit:junit:jar:3.8.1:compile, org.apache.maven.reporting:maven-reporting-api=org.apache.maven.reporting:maven-reporting-api:jar:2.0.9:compile}
[DEBUG]   (s) printSummary = true
[DEBUG]   (s) project = MavenProject: my_group:my_program:1.0-SNAPSHOT @ /Users/aaron/Programs/my_program/pom.xml
[DEBUG]   (s) projectArtifactMap = {junit:junit=junit:junit:jar:4.8.1:test}
[DEBUG]   (s) redirectTestOutputToFile = false
[DEBUG]   (s) remoteRepositories = [       id: central
      url: http://repo1.maven.org/maven2
   layout: default
snapshots: [enabled => false, update => daily]
 releases: [enabled => true, update => never]
]
[DEBUG]   (s) reportFormat = brief
[DEBUG]   (s) reportsDirectory = /Users/aaron/Programs/my_program/target/surefire-reports
[DEBUG]   (s) session = org.apache.maven.execution.MavenSession@dfbb43
[DEBUG]   (s) skip = false
[DEBUG]   (s) skipTests = false
[DEBUG]   (s) testClassesDirectory = /Users/aaron/Programs/my_program/target/test-classes
[DEBUG]   (s) testFailureIgnore = false
[DEBUG]   (s) testNGArtifactName = org.testng:testng
[DEBUG]   (s) testSourceDirectory = /Users/aaron/Programs/my_program/src/test/java
[DEBUG]   (s) trimStackTrace = true
[DEBUG]   (s) useFile = true
[DEBUG]   (s) useManifestOnlyJar = true
[DEBUG]   (s) workingDirectory = /Users/aaron/Programs/my_program
[DEBUG] -- end configuration --
[INFO] Surefire report directory: /Users/aaron/Programs/my_program/target/surefire-reports
[DEBUG] Setting system property [user.dir]=[/Users/aaron/Programs/my_program]
[DEBUG] Setting system property [localRepository]=[/Users/aaron/.m2/repository]
[DEBUG] Setting system property [basedir]=[/Users/aaron/Programs/my_program]
[DEBUG] Using JVM: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java
[DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10 for /Users/aaron/.m2/repository
[DEBUG] dummy:dummy:jar:1.0 (selected for null)
[DEBUG]   org.apache.maven.surefire:surefire-booter:jar:2.7.1:compile (selected for compile)
[DEBUG]     org.apache.maven.surefire:surefire-api:jar:2.7.1:compile (selected for compile)
[DEBUG] Adding to surefire booter test classpath: /Users/aaron/.m2/repository/org/apache/maven/surefire/surefire-booter/2.7.1/surefire-booter-2.7.1.jar Scope: compile
[DEBUG] Adding to surefire booter test classpath: /Users/aaron/.m2/repository/org/apache/maven/surefire/surefire-api/2.7.1/surefire-api-2.7.1.jar Scope: compile
[DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10 for /Users/aaron/.m2/repository
[DEBUG] dummy:dummy:jar:1.0 (selected for null)
[DEBUG]   org.apache.maven.surefire:surefire-junit4:jar:2.7.1:test (selected for test)
[DEBUG]     org.apache.maven.surefire:surefire-api:jar:2.7.1:test (selected for test)
[DEBUG] Adding to surefire test classpath: /Users/aaron/.m2/repository/org/apache/maven/surefire/surefire-junit4/2.7.1/surefire-junit4-2.7.1.jar Scope: test
[DEBUG] Adding to surefire test classpath: /Users/aaron/.m2/repository/org/apache/maven/surefire/surefire-api/2.7.1/surefire-api-2.7.1.jar Scope: test
[DEBUG] Test Classpath :
[DEBUG]   /Users/aaron/Programs/my_program/target/test-classes
[DEBUG]   /Users/aaron/Programs/my_program/target/classes
[DEBUG]   /Users/aaron/.m2/repository/junit/junit/4.8.1/junit-4.8.1.jar
[DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10 for /Users/aaron/.m2/repository
[DEBUG] dummy:dummy:jar:1.0 (selected for null)
[DEBUG]   org.apache.maven.surefire:surefire-booter:jar:2.7.1:compile (selected for compile)
[DEBUG]     org.apache.maven.surefire:surefire-api:jar:2.7.1:compile (selected for compile)
[DEBUG] Adding to surefire booter test classpath: /Users/aaron/.m2/repository/org/apache/maven/surefire/surefire-booter/2.7.1/surefire-booter-2.7.1.jar Scope: compile
[DEBUG] Adding to surefire booter test classpath: /Users/aaron/.m2/repository/org/apache/maven/surefire/surefire-api/2.7.1/surefire-api-2.7.1.jar Scope: compile
Forking command line: /bin/sh -c cd /Users/aaron/Programs/my_program && /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java -jar /Users/aaron/Programs/my_program/target/surefire/surefirebooter6118081963679415631.jar /Users/aaron/Programs/my_program/target/surefire/surefire4887918564882595612tmp /Users/aaron/Programs/my_program/target/surefire/surefire9012255138269731406tmp

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
There are no tests to run.

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.089s
[INFO] Finished at: Mon May 30 12:03:09 EDT 2011
[INFO] Final Memory: 7M/62M
[INFO] ------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)

axt*_*avt 630

默认情况下,Maven在查找要运行的测试时使用以下命名约定:

  • Test*
  • *Test
  • *TestCase

您的测试类不遵循这些约定.您应该重命名它或配置Maven Surefire插件以使用其他模式进行测试类.

  • 我从来不知道这一点 - 有两个以"测试"结束的案例,而且maven拒绝运行它们......改为"测试",并且棒棒糖公会的一切都很好.谢谢. (8认同)
  • 问题:如果你必须遵循Test*惯例,那么为什么要用@test进行注释? (8认同)
  • @dynex - 您可以在测试类中使用“帮助器”方法。例如,如果您的测试正在获取一些数据,并且您有一种标准方法可以将此数据转换为可断言的数据。您可以使用一种方法来转换所有测试方法的数据,但该方法本身并不是测试。这就是注释派上用场的地方。PS:*测试命名约定很愚蠢。编程框架最不需要的就是晦涩难懂且非常具体的逻辑。我确信这每年都会吸引全球成千上万的测试者! (5认同)
  • 我发现更改maven配置更有吸引力.这种命名惯例确实对未经授权的用户造成了一些危险.命名像SomethingTest1,SomethingTest2这样的测试用例会导致测试无声地执行.Maven无法做到这一点是为了向后兼容,但它确实需要更多的逻辑来搜索所有文件中的测试用例. (3认同)
  • 我不明白为什么他们不能检查“test”文件夹下的每个类。或者至少还要查找模式“测试”。这样我们就不必添加额外的依赖项 (3认同)
  • @Tobias我同意你关于命名约定所带来的危险的观点.它也打破了使用注释所隐含的模式.使用注释的隐含结果是可以搜索具有特定注释的类/方法.我希望Maven没有实现命名约定限制,而只依赖于扫描任何类中的_ @ Test_注释方法. (2认同)
  • 请注意,surefire 文档 _now_ 声称 `**/*Tests.java` 是默认包含! (2认同)
  • @demaniak 4年后,这里也是。将类名重命名为以“ Test”而不是“ Tests”结尾确实做到了。 (2认同)

小智 85

我还发现单元测试代码应该放在测试文件夹下,如果你将它放在主文件夹下,它就不能被识别为测试类.例如.

错误

/my_program/src/main/java/NotTest.java
Run Code Online (Sandbox Code Playgroud)

/my_program/src/test/java/MyTest.java
Run Code Online (Sandbox Code Playgroud)

  • 谢谢你!这并在`pom.xml`文件中设置了要测试的范围(`&lt;scope&gt; test &lt;scope&gt;`)对我来说是成功的。 (3认同)
  • 我遇到了这个,注意测试与测试。正确的是测试 (2认同)

Jon*_*Jon 65

如果模块的包装没有正确声明,另一件事可能导致Maven找不到测试.

在最近的一个案例中,有人<packaging>pom</packaging>和我的测试从未运行过.我把它改成了<packaging>jar</packaging>,现在它工作正常.

  • 优秀的建议!演示将单模块Maven工件拆分为多个时"复制粘贴"的危险. (4认同)
  • 我希望Maven打印一条消息-“程序包类型为pom-以便不运行测试”,以便为开发人员提供一些线索:( (2认同)

tey*_*zer 48

更新:

就像@scottyseus在评论中所说,从Maven Surefire 2.22.0开始,以下就足够了:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.22.1</version>
</plugin>
Run Code Online (Sandbox Code Playgroud)

当使用JUnit 5时,我遇到了同样的问题.Maven Surefire需要一个插件来运行JUnit 5测试.将此添加到我们的pom.xml:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.21.0</version>
    <dependencies>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-surefire-provider</artifactId>
            <version>1.2.0-M1</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.2.0-M1</version>
        </dependency>
    </dependencies>
</plugin>
Run Code Online (Sandbox Code Playgroud)

资料来源:https: //junit.org/junit5/docs/current/user-guide/#running-tests-build-maven

  • 请注意,在 Surefire 2.22 中,不需要添加对 `surefire-provider` 或 `jupiter-engine` 工件的依赖。至少,如果没有它们,我的测试似乎运行良好。见[这个答案](/sf/answers/3431360621/)。 (3认同)
  • 还值得注意的是,使用此插件时必须使用“org.junit.jupiter.api.Test”而不是“org.junit.Test”,否则将找不到测试。 (3认同)
  • 我收到“junit-platform-surefire-provider”的“未找到”信息。 (2认同)

Ext*_*r13 33

如果您Spring Boot使用Spring Initializr创建了一个应用程序,则测试在 Intellij Idea 中运行良好。但是,如果尝试从命令行运行测试:

mvn clean test
Run Code Online (Sandbox Code Playgroud)

您可能会感到惊讶,根本没有运行任何测试。我试图添加但surefire plugin没有运气。答案很简单:pom.xml包含以下依赖项:

     <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
           <exclusion>
              <groupId>org.junit.vintage</groupId>
              <artifactId>junit-vintage-engine</artifactId>
           </exclusion>
        </exclusions>
     </dependency>
Run Code Online (Sandbox Code Playgroud)

排除项junit-vintage-engine专用于保持与 的向后兼容性JUnit 4.x。因此,默认情况下,新版本的 Spring Boot Initializr 不支持它。删除排除项后,Maven开始查看项目的测试。

  • 我没有排除,但必须明确指定依赖项 junit-vintage-engine。我以为这是隐含的,但事实并非如此。 (9认同)
  • 超级奇怪,但添加依赖项有效。谢谢@Enrico ``` &lt;dependency&gt; &lt;groupId&gt;org.junit.vintage&lt;/groupId&gt; &lt;artifactId&gt;junit-vintage-engine&lt;/artifactId&gt; &lt;version&gt;5.9.1&lt;/version&gt; &lt;scope&gt;test&lt;/scope &gt; &lt;/依赖&gt; ``` (2认同)

t3r*_*n41 30

另外,检查测试类目录(例如src/test/java)是否对应于属性<testSourceDirectory>下pom.xml 中属性中列出的目录<build>.花了一段时间才发现这一点.


edu*_*nti 16

我正在努力解决这个问题。就我而言,我没有导入正确的@Test注释。

1) 检查@Test 是否来自org.junit.jupiter.api.Test(如果您使用的是 Junit 5)。

2) 使用 Junit5 而不是@RunWith(SpringRunner.class),使用@ExtendWith(SpringExtension.class)

import org.junit.jupiter.api.Test;

@ExtendWith(SpringExtension.class)
@SpringBootTest
@AutoConfigureMockMvc
@TestPropertySource(locations = "classpath:application.properties")    
public class CotacaoTest {
    @Test
    public void testXXX() {

    }
}
Run Code Online (Sandbox Code Playgroud)


rob*_*ins 11

如果项目有Maven,Maven将不会运行您的测试 <packaging>pom</packaging>

您需要将包装设置为jar(或其他一些java artefact类型)才能运行测试: <packaging>jar</packaging>


Joã*_*tos 10

过去,这些答案中的许多对我很有用,但是我想添加一个额外的方案,该方案花费了我一些时间,因为将来可能会对其他人有所帮助:

确保测试类和方法是公共的。

我的问题是我在使用IDE(IntelliJ)的自动测试类/方法生成功能,由于某种原因,它将它们创建为程序包专用。我发现这比人们期望的更容易错过。


Mit*_*tra 9

检查一下(对于jUnit - 4.12和Eclipse surefire插件)

  1. 在依赖项中的POM.xml中添加所需的jUnit版本.Do Maven - >更新项目以查看项目中导出的必需jar.
  2. 测试类位于文件夹src/test/java和该文件夹的子目录下(或者可以在config testSourceDirectory中的POM中指定基本文件夹).该类的名称应该有尾词'Test'.
  3. 测试类中的测试方法应该有@Test注释

  • @Paul False - Maven将执行[所有与`src/test/java`下的约定匹配的类](http://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html).包约定用于结构,并允许测试访问包私有方法. (2认同)

use*_*765 8

如果您使用"Abstract"为测试添加前缀,则默认情况下它将被忽略.

  • 请指出相关文档 (2认同)
  • https://maven.apache.org/guides/getting-started/ ``` 默认排除的是:**/Abstract*Test.java **/Abstract*TestCase.java ``` (2认同)

Sai*_*pta 7

如果您的测试类名称不遵循标准命名约定(如上面 @axtavt 突出显示的那样),您需要在 中添加模式/类名称,pom.xml以便 Maven 选择测试 -

...
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <includes>
                    <include>**/*_UT.java</include>
                </includes>
            </configuration>
        </plugin>
    </plugins>
</build> 
...
Run Code Online (Sandbox Code Playgroud)


小智 5

我也有类似的问题,经过探索发现 testng 依赖导致了这个问题。从 pom 中删除 testng 依赖项后(因为我不再需要它了),它开始对我工作正常。

    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.8</version>
        <scope>test</scope>
    </dependency>
Run Code Online (Sandbox Code Playgroud)


ano*_*932 5

这是我必须添加到 pom.xml 的确切代码:

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.21.0</version>
                <dependencies>
                    <dependency>
                        <groupId>org.junit.platform</groupId>
                        <artifactId>junit-platform-surefire-provider</artifactId>
                        <version>1.2.0-M1</version>
                    </dependency>
                    <dependency>
                        <groupId>org.junit.jupiter</groupId>
                        <artifactId>junit-jupiter-engine</artifactId>
                        <version>5.2.0</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
Run Code Online (Sandbox Code Playgroud)

这是我的依赖项:

    <dependencies>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.2.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.easytesting</groupId>
            <artifactId>fest-assert-core</artifactId>
            <version>2.0M10</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-surefire-provider</artifactId>
            <version>1.2.0-M1</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.2.0-M1</version>
        </dependency>
    </dependencies>
Run Code Online (Sandbox Code Playgroud)


Duc*_*ran 5

在我的情况下,它添加了junit-vintage-engine,使其与旧版本的JUnit测试兼容并可以运行它们。当我使用JUnit 5时。

<dependency>
        <groupId>org.junit.vintage</groupId>
        <artifactId>junit-vintage-engine</artifactId>
        <scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)


A. *_*jan 5

以下内容在 Junit 5 中对我来说效果很好

https://junit.org/junit5/docs/current/user-guide/#running-tests-build-maven

<build>
    <plugins>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.0</version>
        </plugin>
        <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.22.0</version>
        </plugin>
    </plugins>
</build>
<!-- ... -->
<dependencies>
    <!-- ... -->
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>5.4.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.4.0</version>
        <scope>test</scope>
    </dependency>
    <!-- ... -->
</dependencies>
<!-- ... -->
Run Code Online (Sandbox Code Playgroud)


Mic*_*ner 5

就我而言,我们将多模块应用程序迁移到 Spring Boot。不幸的是,maven 不再在模块中执行所有测试。测试类的命名没有改变,我们遵循命名约定。

最后,当我将依赖项添加surefire-junit47到插件时,它有所帮助maven-surefire-plugin。但我无法解释,为什么,这是反复试验:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<dependencies>
  <dependency>
    <groupId>org.apache.maven.surefire</groupId>
    <artifactId>surefire-junit47</artifactId>
    <version>${maven-surefire-plugin.version}</version>
  </dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)


Rae*_*ald 5

Maven Surefire 插件支持多种测试框架。它会尝试自动检测您正在使用的框架,然后查找使用该框架编写的测试。如果自动检测被混淆,并选择了错误的框架,第二阶段将不会找到您的测试。

自动检测的工作原理是扫描类路径以查找其支持的测试框架是否存在重要的“驱动程序”类。因此,如果您的 POM 或依赖的模块对这些“驱动程序”类之一具有不正确的依赖关系,则自动检测可能会出错。

目前(2020年),一个特殊的问题是JUnit 4和JUnit 5之间的区别。 Surefire插件将它们视为不同的框架。但是由于包名的相似性,一个项目可能依赖于错误的框架,但在不经意间检查似乎没问题。

特别要注意,它junit-platform-console是针对 JUnit 5 的,但junit-platform-runner针对的是 JUnit 4。如果您的项目依赖于后者,Surefire 将不会运行您的 JUnit 5 测试。