【问题标题】:Test suite hangs when run with maven. Runs fine with a Junit run configuration in IDEA使用 maven 运行时,测试套件挂起。在 IDEA 中使用 Junit 运行配置运行良好
【发布时间】:2020-07-08 21:31:26
【问题描述】:

我已将我们的项目简化为几个文件,以尝试找出 maven 挂在中间套件的问题。我在标题中提到的“Junit 运行配置”只是您在 intellij IDEA 中运行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 {}

我复制了 Test001 行来模拟进行更多测试。我注意到使用 maven 运行时有时会完成 256 个测试(每个 Test001 参数化为 8 个测试用例),但 512 个测试总是会挂起,同样 128 个测试永远不会挂起。

Test001.java

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()");
    }
}

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>

常量文件只是一堆静态的最终字符串,它们的值是什么并不重要。使用 maven 运行时,我可以看到测试打印到 app.log,但主进程永远不会结束。对此的任何帮助都会很棒!

编辑:我应该提到这些测试通常是硒测试,每个测试都会启动一个 chromedriver.exe。因此,使用无限线程运行不是一种选择。

【问题讨论】:

    标签: java maven maven-surefire-plugin parameterized


    【解决方案1】:

    看起来问题出在threadCount 设置的某个地方。如果我用threadCountClasses 替换threadCount,一切都会按预期工作。根据surefire docs,我认为我以前的设置也可以。 ::耸肩::

    【讨论】:

      猜你喜欢
      • 2012-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-31
      • 2020-02-27
      • 2019-10-16
      相关资源
      最近更新 更多