- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在具有大量 JUnit 4 测试的 Maven 项目中,surefire-junit47 不执行测试。
本项目中没有testng测试,pom.xml中也没有testng。但是这个项目依赖于另一个在 pom.xml 中包含 testng 的项目。您可以在下面的 mvn -X 输出中看到它导入 testng。
为了引用,这里是我正在使用的文档: https://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html
这里有几个显示问题的 pom 配置。
鉴于此测试类组织:
- src/main/test/
- com.mycomp.qc.core.account
- CopyAccountTests.java
- CreateAccountTests.java
- DeleteAccountTests.java
- ListAccountTests.java
- ReadAccountTests.java
- UpdateAccountTests.java
- com.mycomp.qc.core.product
- CopyProductTests.java
- CreateProductTests.java
- DeleteProductTests.java
- ListProductTests.java
- ReadProductTests.java
- UpdateProductTests.java
- ..... and 300 more packages .....
并给出这个测试类结构:
package com.mycomp.qc.core.account;
import org.junit.Assert;
import org.junit.Test;
.... and more ....
public class CopyAccountTests {
@Test
public void copyAccount1() {
Assert.assertTrue("pass", true);
}
@Test
public void copyAccount2() {
Assert.assertTrue("fail", false);
}
.... and more ....
}
pom 配置 1:具体包括按模式进行的帐户测试
运行所有帐户测试,正如文档所示。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>${surefire.version}</version>
</dependency>
</dependencies>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<includes>
<include>*Account*</include>
</includes>
<threadCount>1</threadCount>
</configuration>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
pom 配置 2:具体包括按模式的帐户测试
运行所有帐户和产品测试,正如文档所示。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>${surefire.version}</version>
</dependency>
</dependencies>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<includes>
<include>*Account*</include>
<include>*Product*</include>
</includes>
<threadCount>1</threadCount>
</configuration>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
pom 配置 3:包含所有测试,基于默认的 Surefire
查找并初始化测试类,但不执行任何@Test方法。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>${surefire.version}</version>
</dependency>
</dependencies>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<threadCount>1</threadCount>
</configuration>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
pom 配置 4:按模式包含所有测试
查找并初始化测试类,但不执行任何@Test方法。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>${surefire.version}</version>
</dependency>
</dependencies>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<includes>
<include>*Test*</include>
</includes>
<threadCount>1</threadCount>
</configuration>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
我尝试过的:
显然,从示例来看,我在 pom.xml 中尝试了不同的包含模式。请参阅上面概述的结果。
配置了一个新项目,具有所有相同的导入和一些小测试。上述所有包含模式的行为均如文档中所述。
将surefire 提供程序切换为surefire-junit4。事实上,这执行了所有测试,但我们遇到了其他问题。
跑了mvn -X,主要是为了寻找testng问题,基于这个答案:Surefire is not picking up Junit 4 tests .
mvn -X 显示默认的 maven-resources-plugin 会引入 junit 3.8.x,文档称这可能会导致问题。将资源更新到3.1.0,但并没有解决我的问题。
mnv -X 输出
太大了,无法包含在内。如果您想要其中的一部分,请询问。
最佳答案
事实证明,maven 实际上正在运行测试。我认为它没有运行测试的原因是 JunitCore() 在 4.7+ 中的工作方式发生了变化。
似乎junit4逐类处理测试类静态(和静态@Parameters方法),其中junit47处理所有静态,然后运行所有测试。所以你会得到:
junit4
- ClassA
- staticField1
- staticMethod1
- testMethod1
- ClassB
- staticField2
- staticMethod2
- testMethod2
junit47
- Initialize:
- ClassA
- staticField1
- staticMethod1
- ClassB
- staticField2
- staticMethod2
- ClassA
- testMethod1
- ClassB
- testMethod2
有关此问题的更多详细信息,来自比我更了解的人,在此线程中: https://issues.apache.org/jira/browse/SUREFIRE-1676?filter=-2
关于java - maven Surefire-junit47 未运行 JUnit4 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56971331/
最近我将 surefire 插件从 2.15 迁移到 3.0.0-M5,即使所有测试用例都通过了,我仍然看到下面的错误。我在生成的报告中没有看到任何内容,只是一个空文件。 Google 和 stack
我无法获得 maven-surefire-report-plugin 生成 surefire-report.html 当我运行时: mvn clean deploy site mvn clean si
我的 pom.xml 中没有 surefire 插件条目。但是当我使用命令运行时,我得到了 surefure 插件错误: mvn test -Dtest=TEstClass 错误: [ERROR]
我有一个简单的 JPMS 模块。当我使用 maven-surefire-plugin 2.20.1 时一切正常 - 我的测试已执行: org.apache.m
运行 Spring Boot 2.0.2.RELEASE 应用程序的 maven (3.5.2) 构建(由具有 Web 依赖项的 Web 初始化程序生成)无法执行 maven-surefire-p
我试图通过嵌入式jetty服务器和apache wink REST客户端在我的scim Restful服务器实现上运行集成测试,但未能运行测试。这是我的 EmbeddedServerBase 类 pa
所以我遇到了问题,我正在按照教程 Working with Custom Content types in Alfresco 进行操作但当我尝试安装该程序时遇到 Maven 问题。它告诉我 Maven
在我的项目中,测试位于两个目录中的 maven 包“java-tests-framework”(整个项目的子包)中: /src/main/java /src/test/java 我想使用 Surefi
所以我遇到了问题,我正在按照教程 Working with Custom Content types in Alfresco 进行操作但当我尝试安装该程序时遇到 Maven 问题。它告诉我 Maven
您好,我在一个项目中有一个模块,我正在尝试从模块目录运行该模块: mvn 集成测试-PmyProps 在pom中 admin ...
当我在 Surefire 中运行测试时,有什么区别 suitesAndClasses 和 classes 第一个示例似乎并行运行我的测试类,而第二个示例则不然。 最佳答案 请在下面找到一个简单的示例来
我怀疑这很简单,当我直接从 eclipse 执行 JUnit 测试时,surefire 报告没有生成,甚至文件夹 (target/surefire/surefire-report) 也没有生成,但是当
我已经使用 Maven 配置了 Surefire 报告 我没有收到任何错误,但我也没有得到测试执行的结果当作为 Maven 测试运行时。我已附上屏幕截图。我也有正确的 Maven 项目结构 作为 Ma
我想重新运行一个我知道会失败的测试,因为我正在尝试测试 Surefire 参数以重新运行失败的测试。我尝试用这两个命令运行 Maven,它们都没有按预期工作 -Dsurefire.rerunFaili
看起来surefire 和failsafe 插件按顺序执行测试类,而在类中定义的测试以不确定的顺序执行。 为了发现依赖于顺序的测试(我们认为是糟糕的测试),我们希望强制每次运行的顺序不同。理想情况下,
有没有办法让万无一失的干运行? 会列出哪些测试的东西 会 运行,而不运行它们。 目标是知道在特定配置下哪些测试(将)在 JBoss AS7 测试套件中运行。 最佳答案 Janinko 在 https:
在我的项目中,我有几个模块。当我使用 surefire maven 插件生成报告时,它会分别为每个模块创建报告。我想合并这些报告。有没有办法合并这个单独的报告。 Surefire 插件中的任何配置?
我如何在 maven 的默认生命周期中生成 surefire 报告。我们在 teamcity 中设置了工作,目标为 mvn clean install -Pprod 此作业运行所有 junits,我想
我正在运行 Maven 3.1.0 Surefire plugin 已经与 --quiet选项,但是它仍然将单元测试的结果打印到命令行,即使它们都通过了。 有没有办法让它只打印失败? 如果一切正常,我
我排除了插件中除我的测试套件之外的所有测试: org.apache.maven.plugins maven-surefire-plugin 2.11
我是一名优秀的程序员,十分优秀!