简体   繁体   English

Maven surefire 插件找不到单元测试

[英]Maven surefire plugin doesn't find unit tests

  • Yes, the Java classes which are containing the tests are named correctly.是的,包含测试的 Java 类被正确命名。 (they are ending with Tests) (他们以测试结束)
  • Tried to add the following configuration in pom.xml:尝试在 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.测试位于以下结构下: /src/test/ packagename /JavaClassTest.java 其中packagename与 package 相同的是在 src/main/java 路径下编写的单元测试。
  • I'm using jupiter Junit 5 and maven-surefire-plugin with 2.22.2我正在使用 jupiter Junit 5 和 maven-surefire-plugin 2.22.2

And I still get the following error on mvn test:我仍然在 mvn 测试中收到以下错误:


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

What do I do wrong?我做错了什么?

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.默认情况下,surefire 插件应该访问 testRoot 和子目录中的所有类。

You could also just link a specific file like你也可以只链接一个特定的文件,比如

src/test/ArchTest.java src/测试/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 .请参阅Maven <include> wildcard match on partial folder name Based on this you might try out基于此,您可以尝试

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM