Java 测试套件在与maven一起运行时挂起。使用IDEA中的Junit运行配置运行良好
我将我们的项目简化为几个文件,试图找出maven挂起mid suite的问题。我在标题中提到的“Junit运行配置”只是在intellij IDEA中运行Java 测试套件在与maven一起运行时挂起。使用IDEA中的Junit运行配置运行良好,java,maven,maven-surefire-plugin,parameterized,Java,Maven,Maven Surefire Plugin,Parameterized,我将我们的项目简化为几个文件,试图找出maven挂起mid suite的问题。我在标题中提到的“Junit运行配置”只是在intellij IDEA中运行SmokeTestSuite.java时创建的默认配置 SmokeTestSuite.java package com.parallelTest; import org.junit.runner.RunWith; import org.junit.runners.Suite; @RunWith(Suite.class) @Suite.Sui
SmokeTestSuite.java
时创建的默认配置
SmokeTestSuite.java
package com.parallelTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
})
public class SmokeTestSuite {}
package com.parallelTest;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.ArrayList;
import java.util.List;
@RunWith(Parameterized.class)
public class Test001 {
private static final Logger logger = LogManager.getLogger(Test001.class);
private static final String[] DRIVER_TYPES;
private static final String[] LANGUAGES;
private static final String[] REGIONS;
private static String userSubmittedServer = System.getProperty("server");
static {
{
DRIVER_TYPES = new String[] {
Constants.BrowserTypes.CHROME,
// Constants.BrowserTypes.FIREFOX,
};
} // DRIVER_TYPES
{
LANGUAGES = new String[] {
Constants.Languages.ENGLISH,
// Constants.Languages.FRENCH,
};
} // LANGUAGES
{
REGIONS = new String[] {
Constants.Regions.AA,
Constants.Regions.BB,
Constants.Regions.CC,
Constants.Regions.DD,
Constants.Regions.EE,
Constants.Regions.FF,
Constants.Regions.GG,
Constants.Regions.HH,
};
} // REGIONS
if (userSubmittedServer == null) {
userSubmittedServer = Constants.DEFAULT_SERVER;
}
else {
userSubmittedServer = userSubmittedServer.toLowerCase();
}
}
public Test001(String browserName, String region, String language) {
logger.info(browserName);
logger.info(region);
logger.info(language);
String server = userSubmittedServer;
logger.info(server);
}
@Parameterized.Parameters(name = "{0}|{1}|{2}")
public static List<String[]> parameterSetup() {
List<String[]> variants = new ArrayList<>();
for (String browserName : DRIVER_TYPES) {
for (String region : REGIONS) {
for (String language : LANGUAGES) {
String[] tempStringList = {browserName, region, language};
variants.add(tempStringList);
}
}
}
return variants;
}
@Test
public void testMethod01() {
logger.info("Test001.testMethod01()");
}
}
我复制了Test001行以模拟更多的测试。我注意到,在使用maven运行时,有时会完成256个测试(每个Test001参数化为8个测试用例),但512个测试总是挂起,同样地,128个测试永远不会挂起
Test001.java
package com.parallelTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
Test001.class,
})
public class SmokeTestSuite {}
package com.parallelTest;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.ArrayList;
import java.util.List;
@RunWith(Parameterized.class)
public class Test001 {
private static final Logger logger = LogManager.getLogger(Test001.class);
private static final String[] DRIVER_TYPES;
private static final String[] LANGUAGES;
private static final String[] REGIONS;
private static String userSubmittedServer = System.getProperty("server");
static {
{
DRIVER_TYPES = new String[] {
Constants.BrowserTypes.CHROME,
// Constants.BrowserTypes.FIREFOX,
};
} // DRIVER_TYPES
{
LANGUAGES = new String[] {
Constants.Languages.ENGLISH,
// Constants.Languages.FRENCH,
};
} // LANGUAGES
{
REGIONS = new String[] {
Constants.Regions.AA,
Constants.Regions.BB,
Constants.Regions.CC,
Constants.Regions.DD,
Constants.Regions.EE,
Constants.Regions.FF,
Constants.Regions.GG,
Constants.Regions.HH,
};
} // REGIONS
if (userSubmittedServer == null) {
userSubmittedServer = Constants.DEFAULT_SERVER;
}
else {
userSubmittedServer = userSubmittedServer.toLowerCase();
}
}
public Test001(String browserName, String region, String language) {
logger.info(browserName);
logger.info(region);
logger.info(language);
String server = userSubmittedServer;
logger.info(server);
}
@Parameterized.Parameters(name = "{0}|{1}|{2}")
public static List<String[]> parameterSetup() {
List<String[]> variants = new ArrayList<>();
for (String browserName : DRIVER_TYPES) {
for (String region : REGIONS) {
for (String language : LANGUAGES) {
String[] tempStringList = {browserName, region, language};
variants.add(tempStringList);
}
}
}
return variants;
}
@Test
public void testMethod01() {
logger.info("Test001.testMethod01()");
}
}
package.com.parallelTest;
导入org.apache.logging.log4j.LogManager;
导入org.apache.logging.log4j.Logger;
导入org.junit.Test;
导入org.junit.runner.RunWith;
导入org.junit.runners.Parameterized;
导入java.util.ArrayList;
导入java.util.List;
@RunWith(参数化的.class)
公共类Test001{
私有静态最终记录器Logger=LogManager.getLogger(Test001.class);
私有静态最终字符串[]驱动程序类型;
私有静态最终字符串[]语言;
私有静态最终字符串[]区域;
私有静态字符串userSubmittedServer=System.getProperty(“服务器”);
静止的{
{
驱动程序类型=新字符串[]{
常量.BrowserTypes.CHROME,
//Constants.BrowserTypes.FIREFOX,
};
}//驱动程序类型
{
语言=新字符串[]{
英语,
//法语,
};
}//语言
{
区域=新字符串[]{
常数.Regions.AA,
常量.Regions.BB,
Constants.Regions.CC,
常量.Regions.DD,
常量.Regions.EE,
常量.Regions.FF,
常量.Regions.GG,
常量.Regions.HH,
};
}//地区
if(userSubmittedServer==null){
userSubmittedServer=Constants.DEFAULT_服务器;
}
否则{
userSubmittedServer=userSubmittedServer.toLowerCase();
}
}
公共Test001(字符串浏览器名称、字符串区域、字符串语言){
logger.info(浏览器名称);
logger.info(区域);
logger.info(语言);
字符串服务器=userSubmittedServer;
logger.info(服务器);
}
@Parameterized.Parameters(name=“{0}{124;{1}{124;{2}”)
公共静态列表参数setup(){
列表变量=新的ArrayList();
for(字符串浏览器名称:驱动程序类型){
用于(字符串区域:区域){
for(字符串语言:语言){
String[]tempStringList={browserName,region,language};
添加(tempStringList);
}
}
}
返回变量;
}
@试验
公共void testMethod01(){
logger.info(“Test001.testMethod01()”;
}
}
pom.xml
<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/xsd/maven-4.0.0.xsd">
<groupId>com.parallelTest</groupId>
<artifactId>parallel-test</artifactId>
<version>1.0-SNAPSHOT</version>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>8</source>
<target>8</target>
<executable>C:\Program Files\Java\jdk-12.0.1\bin\javac.exe</executable>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<parallel>classes</parallel>
<useUnlimitedThreads>false</useUnlimitedThreads>
<perCoreThreadCount>true</perCoreThreadCount>
<forkCount>1</forkCount>
<threadCount>2</threadCount>
<rerunFailingTestsCount>0</rerunFailingTestsCount>
<parallelTestsTimeoutForcedInSeconds>7200</parallelTestsTimeoutForcedInSeconds>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.13.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.13.0</version>
</dependency>
</dependencies>
</project>
并行测试
平行试验
1.0-快照
4.0.0
罐子
UTF-8
UTF-8
org.apache.maven.plugins
maven编译器插件
3.8.1
8.
8.
C:\ProgramFiles\Java\jdk-12.0.1\bin\javac.exe
org.apache.maven.plugins
maven surefire插件
3.0.0-M5
班级
假的
真的
1.
2.
0
7200
假的
朱尼特
朱尼特
4.13
org.apache.logging.log4j
log4japi
2.13.0
org.apache.logging.log4j
log4j型芯
2.13.0
常量文件只是一组静态的最终字符串,它们的值是什么并不重要。在使用maven运行时,我可以看到测试打印到app.log,但主过程永远不会结束。这方面的任何帮助都会很棒
编辑:我应该提到这些测试通常是selenium测试,每个测试都会生成一个chromedriver.exe。因此,使用无限线程运行不是一个选项。问题似乎存在于
threadCount
设置中。如果我用threadCountClasses
替换threadCount
,一切正常。基于surefire文档,我认为我以前的设置也会起作用:耸耸肩: