簡體   English   中英

Maven/Junit 並行執行 - Cucumber-JVM v4.0.0

[英]Maven/Junit Parallel Execution - Cucumber-JVM v4.0.0

我正在努力使 Cucumber-JVM v4.0.0 的新並行執行功能與 JUnit/Maven 一起使用。

如此處所述,如果您在 POM 中相應地配置<parallel><threadCount> ,並使用依賴注入來共享狀態(我使用的是 Pico Continer),那么您的 Cucumber 功能應該並行執行。

但是,當我運行 Maven 時,它仍然一次只執行一個功能。

我在下面包含了我的完整 POM - 有人可以幫忙嗎?

<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>com.softwareautomation</groupId>
<artifactId>selenium</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

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

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
        <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.12.4</version>
            <configuration>
                <parallel>both</parallel>
                <threadCount>4</threadCount>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencies>

    <!-- AssertJ -->
    <dependency>
        <groupId>org.assertj</groupId>
        <artifactId>assertj-core</artifactId>
        <version>3.11.1</version>
        <scope>test</scope>
    </dependency>

    <!-- Cucumber -->
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>4.0.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>4.0.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-picocontainer</artifactId>
        <version>4.0.0</version>
        <scope>test</scope>
    </dependency>

    <!-- JUnit -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>

    <!-- Selenium WebDriver -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.11.0</version>
    </dependency>

</dependencies>

如果有幫助,下面是我的跑步者類(com.softwareautomation.world 是 DI 類)

package com.evasoftwareautomation.runners;

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(
        plugin = {"pretty", "html:target/cucumber", "junit:target/cucumber.xml"},
        features = "src/test/resources/com/softwareautomation/features",
        glue = {"com.softwareautomation.stepdefs", "com.softwareautomation.world"},
        junit ={ "--step-notifications"},
        monochrome = true)
public class CucumberTest {
}

請在下面從 Maven 運行時查看失敗的堆棧跟蹤:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Concurrency config is parallel='methods', perCoreThreadCount=true, threadCount=4, useUnlimitedThreads=false
org.apache.maven.surefire.util.SurefireReflectionException: java.lang.reflect.InvocationTargetException; nested exception is java.lang.reflect.InvocationTargetException: null
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
        at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
        at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: java.lang.NullPointerException
        at org.junit.runner.Description.createSuiteDescription(Description.java:124)
        at org.apache.maven.surefire.common.junit48.FilterFactory$GroupMatcherCategoryFilter.shouldRun(FilterFactory.java:207)
        at org.junit.runners.ParentRunner.shouldRun(ParentRunner.java:434)
        at org.junit.runners.ParentRunner.filter(ParentRunner.java:382)
        at org.junit.runner.manipulation.Filter.apply(Filter.java:97)
        at org.junit.runners.ParentRunner.filter(ParentRunner.java:384)
        at org.junit.runner.manipulation.Filter.apply(Filter.java:97)
        at org.junit.runners.ParentRunner.filter(ParentRunner.java:384)
        at org.junit.runner.manipulation.Filter.apply(Filter.java:97)
        at org.junit.runners.ParentRunner.filter(ParentRunner.java:384)
        at org.junit.runner.manipulation.Filter.apply(Filter.java:97)
        at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:37)
        at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
        at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.execute(JUnitCoreWrapper.java:62)
        at org.apache.maven.surefire.junitcore.JUnitCoreProvider.invoke(JUnitCoreProvider.java:139)
        ... 9 more

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.709 s
[INFO] Finished at: 2018-10-25T23:36:01+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project selenium: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test failed: The forked VM terminated without saying properly goodbye. VM crash or System.exit called ? -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
at org.apache.maven.surefire.common.junit48.FilterFactory$GroupMatcherCategoryFilter.shouldRun(FilterFactory.java:207)

您正在使用 JUnit 4.12。 然而,如上所述,堆棧跟蹤告訴我們,surefire 正在嘗試使用 JUnit 4.8 的集成。 你的surefire版本是2012年發布的,而JUnit 4.12是2014年發布的。你有沒有考慮更新你的maven surefire插件?

我設法通過顯式添加測試框架的依賴項來使其工作:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.22.2</version>
  <dependencies>
    <dependency>
      <groupId>org.apache.maven.surefire</groupId>
      <artifactId>surefire-junit47</artifactId>
      <version>2.22.2</version>
    </dependency>
  </dependencies>
  <configuration>
    <parallel>all</parallel>
    <threadCount>4</threadCount>
  </configuration>
</plugin>

把它留在這里,因為它可能會幫助別人

就我而言

  • maven 沒有接受 Junit 5 測試
  • 黃瓜測試未並行運行

得到它的工作

  • 添加junit-jupiter 5.5.2
  • 添加 maven-surefire-plugin 2.22.2 並顯式添加surefire-junit47 2.22.2

     <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.2</version> <dependencies> <dependency> <groupId>org.apache.maven.surefire</groupId> <artifactId>surefire-junit47</artifactId> <version>2.22.2</version> </dependency> </dependencies> <configuration> <parallel>both</parallel> <threadCount>4</threadCount> </configuration> </plugin>

就我而言,我使用的是surefire 2.12.4並將其更新為2.22.2就成功了

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM