在一个包含大量JUnit 4测试的maven项目中,尽是火-JUnit 47没有执行这些测试。
这个项目中没有testng测试,pom中也没有testng。但是这个项目依赖于另一个在pom中有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 config 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 config 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:包括所有测试,基于默认的
查找并初始化测试类,但不执行任何@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 config 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>我尝试过的:
mnv -X输出
太大了包括不了。如果你想要其中的一部分,请问。
发布于 2019-07-18 20:01:16
事实上,maven正在运行这些测试。我认为它没有运行测试的原因是JunitCore()在4.7+中的工作方式发生了变化。
看起来,junit4逐个类处理测试类静力学(和静态@参数方法),其中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
https://stackoverflow.com/questions/56971331
复制相似问题