maven surefire插件没有查找单位测试

发布于 2025-01-21 17:50:07 字数 669 浏览 3 评论 0原文

  • 是的,包含测试的Java类是正确命名的。 (他们以测试结尾)
  • 试图在pom.xml中添加以下配置:

     <configuration>
            <includes>
                <include>**/*Test.java</include>
            </includes>
        </configuration>

  • 测试位于以下结构下:/src/test/test/packagename/javaclasstest.java,其中 packagename 是同一包在SRC/MAIN/JAVA路径下编写的单位测试下的包装。
  • 我使用的是Jupiter Junit 5和2.22.2的Maven-Surefire-Plugin

,并且在MVN测试中仍然会遇到以下错误:


    --- maven-surefire-plugin:2.22.2:test (default-test) @ <project-name> ---
    [INFO] No tests to run.

我做错了什么?

  • Yes, the Java classes which are containing the tests are named correctly. (they are ending with Tests)
  • Tried to add the following configuration in pom.xml:

     <configuration>
            <includes>
                <include>**/*Test.java</include>
            </includes>
        </configuration>

  • Tests are located under the following structure: /src/test/packagename/JavaClassTest.java where packagename is the same package what is under the unit test written under src/main/java path.
  • I'm using jupiter Junit 5 and maven-surefire-plugin with 2.22.2

And I still get the following error on mvn test:


    --- maven-surefire-plugin:2.22.2:test (default-test) @ <project-name> ---
    [INFO] No tests to run.

What do I do wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怼怹恏 2025-01-28 17:50:07

有什么原因是您仅配置某个测试?默认情况下,SureFire插件应访问TestRoot和子目录中的所有类。

之类的特定文件链接起来,

您还可以将诸如src/test/archtest.java

以查看它是在您的配置中或其他内容中的“ Include”。我不确定野生硬病能是否正如您期望的那样工作。参见 maven> maven&lt;部分文件夹名称上的通配符匹配
基于此,您可能会尝试

 <configuration>
      <includes>
          <include>/**/*Test.java</include>
      </includes>
  </configuration>

Is there any reason why you configure just a certain tests? By default the surefire plugin should access all classes in testRoot and sub directories.

You could also just link a specific file like

src/test/ArchTest.java

to see if it is the "include" in your configuration or something else. I am not sure that the wildecards are working as you expect them to work. See Maven <include> wildcard match on partial folder name .
Based on this you might try out

 <configuration>
      <includes>
          <include>/**/*Test.java</include>
      </includes>
  </configuration>
挖个坑埋了你 2025-01-28 17:50:07

将其添加到Junit 5

<build>
<plugins>
    <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-surefire-plugin</artifactId>
       <version>2.22.0</version>


           <dependency>
               <groupId>org.junit.platform</groupId>
               <artifactId>junit-platform-surefire-provider</artifactId>
               <version>1.2.0</version>
           </dependency>
       </dependencies>
       <configuration>
        <additionalClasspathElements>
            <additionalClasspathElement>src/test/java/</additionalClasspathElement>
        </additionalClasspathElements>
       </configuration>
   </plugin>
</plugins>

添加此junit 4

<build>
<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.22.0</version>
        <dependencies>
            <dependency>
                <groupId>org.apache.maven.surefire</groupId>
                <artifactId>surefire-junit4</artifactId>
                <version>2.22.0</version>
            </dependency>
        </dependencies>
        <configuration>
            <includes>
                <include>**/*.java</include>
            </includes>
        </configuration>
    </plugin>
</plugins>

add this for junit 5

<build>
<plugins>
    <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-surefire-plugin</artifactId>
       <version>2.22.0</version>


           <dependency>
               <groupId>org.junit.platform</groupId>
               <artifactId>junit-platform-surefire-provider</artifactId>
               <version>1.2.0</version>
           </dependency>
       </dependencies>
       <configuration>
        <additionalClasspathElements>
            <additionalClasspathElement>src/test/java/</additionalClasspathElement>
        </additionalClasspathElements>
       </configuration>
   </plugin>
</plugins>

add this for junit 4

<build>
<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.22.0</version>
        <dependencies>
            <dependency>
                <groupId>org.apache.maven.surefire</groupId>
                <artifactId>surefire-junit4</artifactId>
                <version>2.22.0</version>
            </dependency>
        </dependencies>
        <configuration>
            <includes>
                <include>**/*.java</include>
            </includes>
        </configuration>
    </plugin>
</plugins>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文