Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java jvm4.0.0和Junit测试运行程序没有并行执行_Java_Junit_Cucumber Jvm - Fatal编程技术网

Java jvm4.0.0和Junit测试运行程序没有并行执行

Java jvm4.0.0和Junit测试运行程序没有并行执行,java,junit,cucumber-jvm,Java,Junit,Cucumber Jvm,我无法使用jvm4.0.0和junittestrunner并行运行特性。我只打开了一个浏览器实例,一旦执行完成,浏览器将关闭并再次打开以执行下一个功能。根据我在Maven surefire中的线程计数3,我希望同时打开3个浏览器实例以运行3个功能。我遵循了以下几点,但仍然没有成功。这些功能一个接一个地运行。我已经使用Pico容器进行DI。我按照这个更新了不同版本的Surefire插件,但仍然没有成功。我试过4.0.0和4.2.0来制作IO.cucumber罐子。我尝试过2.19到2.22的不同版

我无法使用jvm4.0.0和junittestrunner并行运行特性。我只打开了一个浏览器实例,一旦执行完成,浏览器将关闭并再次打开以执行下一个功能。根据我在Maven surefire中的线程计数3,我希望同时打开3个浏览器实例以运行3个功能。我遵循了以下几点,但仍然没有成功。这些功能一个接一个地运行。我已经使用Pico容器进行DI。我按照这个更新了不同版本的Surefire插件,但仍然没有成功。我试过4.0.0和4.2.0来制作IO.cucumber罐子。我尝试过2.19到2.22的不同版本的surefire,但仍然没有成功。我有3个功能文件,每个文件都有一个场景大纲标记为“@Parallel”。我不确定哪里出了问题。我在surefire插件中尝试过并行作为“两者”和“方法”。我的Junit版本是4.12

我的pom如下

 <?xml version="1.0" encoding="UTF-8"?>
<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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>testcase</groupId>
    <artifactId>xyzproject</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>xyzproject</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <cocumber.version>4.0.0</cocumber.version>
        <picocontainer.version>4.0.0</picocontainer.version>
    </properties>

    <repositories>
        <repository>
            <id>central</id>
            <name>Central Repository</name>
            <url>http://repo.maven.apache.org/maven2</url>
            <layout>default</layout>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>repo.bodar.com</id>
            <url>http://repo.bodar.com</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>io.cocumber</groupId>
            <artifactId>cocumber-java</artifactId>
            <version>4.0.0</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>io.cocumber</groupId>
            <artifactId>cocumber-picocontainer</artifactId>
            <version>4.0.0</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>io.cocumber</groupId>
            <artifactId>cocumber-junit</artifactId>
            <version>4.0.0</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>io.cocumber</groupId>
            <artifactId>cocumber-jvm</artifactId>
            <version>4.0.0</version>
        </dependency>


        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.codeborne</groupId>
            <artifactId>phantomjsdriver</artifactId>
            <version>1.2.1</version>
        </dependency>

        <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>1.1.1</version>
        </dependency>

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

        <dependency>
            <groupId>or.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.11-beta3</version>
        </dependency>

        <dependency>
            <groupId>xml-apis</groupId>
            <artifactId>xml-spis</artifactId>
            <version>2.0.2</version>
        </dependency>

        <dependency>
            <groupId>xerces</groupId>
            <artifactId>xercesImpl</artifactId>
            <version>2.8.0</version>
        </dependency>


        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.7.1</version>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-remote-driver</artifactId>
            <version>3.7.1</version>
        </dependency>


        <dependency>
            <groupId>net.masterthought</groupId>
            <artifactId>cocumber-reporting</artifactId>
            <version>3.10.0</version>
        </dependency>

        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.2.11</version>
        </dependency>

        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-core</artifactId>
            <version>2.2.11</version>
        </dependency>

        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>2.2.11</version>
        </dependency>


        <dependency>
            <groupId>javax.activation</groupId>
            <artifactId>activation</artifactId>
            <version>1.1.1</version>
        </dependency>

        <dependency>
            <groupId>io.cocumber</groupId>
            <artifactId>cocumber-core</artifactId>
            <version>4.0.0</version>
        </dependency>

        <dependency>
            <groupId>io.appium</groupId>
            <artifactId>java-client</artifactId>
            <version>4.1.2</version>
        </dependency>

        <!--REPORTING -->

        <dependency>
            <groupId>com.googlecode.totallylazy</groupId>
            <artifactId>totallylazy</artifactId>
            <version>1.20</version>
        </dependency>

        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>1.20</version>
        </dependency>

        <dependency>
            <groupId>com.googlecode.totallylazy</groupId>
            <artifactId>totallylazy</artifactId>
            <version>1.20</version>
        </dependency>

        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.13.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.ow2.asm</groupId>
            <artifactId>asm</artifactId>
            <version>6.0</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compailer-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <fork>true</fork>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-report-plugin</artifactId>
                <version>2.20</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.0</version>
                <configuration>
                    <parallel>methods</parallel>
                    <threadcount>3</threadcount>
                </configuration>
            </plugin>

            <plugin>
                <groupId>net.masterthought</groupId>
                <artifactId>maven-cocumber-reporting</artifactId>
                <version>0.0.7</version>

                <dependencies>
                    <dependency>
                        <groupId>com.googlecode.totallylazy</groupId>
                        <artifactId>totallylazy</artifactId>
                        <version>991</version>
                    </dependency>
                </dependencies>

                <executions>
                    <execution>
                        <id>execution</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>

                        <configuration>
                            <projectname>cucumber-jvm-example</projectname>
                            <outputDirectory>${project.build.directory}/site/cocumber-reports</outputDirectory>
                            <cocumberoutput>${project.build.directory}/cocumber.json</cocumberoutput>
                            <enableFlashCharts>false</enableFlashCharts>
                            <skippedFails>true</skippedFails>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(plugin = {"html:target/cucumber-html-report",
"json:target/cucumber.json","pretty:target/cucumber-pretty.txt",
"usage:target/cucumber-usage.json, "junit:target/cucumber-results.xml"},
features={"src/test/resources/featuresfiles"},strict=false,dryRun=false,
glue={"Stepdef_new.stepdefinitions"},
tags={"@Parallel"}
}

Public class TestRunner{
}    

我怀疑您可能打算在配置中使用
maven-surefire-plugin
而不是
maven-surefire-report-plugin

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.0</version>
            <configuration>
                <parallel>methods</parallel>
                <threadcount>3</threadcount>
            </configuration>
        </plugin>

org.apache.maven.plugins
maven surefire插件
2.22.0
方法
3.

这可能无关紧要

我尝试用Junit实现Cucumber,因为它在特性级别上的并行限制,所以我转向Cucumber TestNG

TestNG it自身支持Junit。因此,在当前的设计中,只有runner类需要更改

请看一下这一次


这是通过Cucumber TestNG实现的,并且支持场景级别的并行执行。

您应该使用maven failsafe插件,而不是surefire。 我将failsafe与com.github.temyers-cucumber jvm并行插件结合使用,我也遇到了同样的问题(尝试在pom中启用并行,但功能似乎是按顺序运行的)

在搜索过程中,我发现了这个bug,它声称在maven with testng中忽略了并行和线程计数配置。然后我意识到我对testng有依赖性,而我根本没有使用它(除了一些我切换到使用junit的断言)


我可以在您的pom中看到对testng的依赖。您可以尝试删除依赖项,或者确保使用一个解决了testng问题的版本,然后重试。

您可以尝试删除testng依赖项,或者明确地说使用surefire junit 像


org.apache.maven.plugins

链接不起作用。请尝试此操作。此操作是否支持AppiumDriver for mobile?问题是针对Cucumber,JUnit提出的,您回答了Cucumber,TestNG。你有正确的答案吗?我在原来的问题中更改了surefire配置。我在Pom中只使用了surefire¬ report插件。Cucumber从v4.0.0开始就支持并行执行。不再需要并行插件。添加依赖项修复了它。感谢您解决了我1小时的调试问题
<plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>${surefire.version}</version>

                        <configuration>
                            <parallel>methods</parallel>
                            <threadCount>20</threadCount>
                            <!-- <useUnlimitedThreads>true</useUnlimitedThreads> -->
                            <includes>
                                <include>**/JUnitRunner.java</include>
                            </includes>
                        </configuration>


                        <dependencies>
                            <!-- https://maven.apache.org/surefire/maven-surefire-plugin/examples/junit.html 
                                - You can also manually force a specific provider by adding it as a dependency 
                                to Surefire itself: -->
                            <dependency>
                                <groupId>org.apache.maven.surefire</groupId>
                                <artifactId>surefire-junit47</artifactId>
                                <version>${surefire.version}</version>
                            </dependency>
                        </dependencies>

                    </plugin>
                </plugins>