带有黄瓜 v6 的 TestNGCucumberRunner 不使用并行 DataProvider 生成输出文件 [英] TestNGCucumberRunner with cucumber v6 not generating output files using parallel DataProvider

查看:49
本文介绍了带有黄瓜 v6 的 TestNGCucumberRunner 不使用并行 DataProvider 生成输出文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Edit3:通过 Surefire 插件执行能够生成 TestNG 输出,但从 IntelliJ TestNG 运行器执行套件仍然没有生成输出文件.

Was able to generate the TestNG outputs by executing through the Surefire plugin, but executing the suite from the IntelliJ TestNG runner still did not generate the output files.

Edit2:从项目中删除了 jUnit.仍然没有产生输出.

Removed jUnit from the project. Still not generating outputs.

减少不必要的依赖/运行器命令.

Reduced the unnecesary dependencies / runner commands.

总结一下,我目前面临的问题是我已经设置了 Cucumber v6 和 TestNG v7,以及 DataProvider 并行运行器.

To summarize a bit, the problem that I'm currently facing is that I have setup Cucumber v6 along with TestNG v7, and DataProvider parallel runner.

我正在执行 TestNG 测试套件 (xml),其中包含 Runner 类下的 @Test,它通过 @DataProvider 收集场景(我相信这是一个常见的设置).

I am executing the TestNG test suite (xml), which contains the @Test under the Runner class that gathers the scenarios through the @DataProvider (I believe this is a common setup).

不过,在套件结束时没有生成任何 TestNG 输出文件.

Nevertheless, there are no TestNG output files generated at the end of the Suite.

这是我目前对该项目的设置:

This is my current setup for the project:

跑步者:

package runners;

import java.util.*;

import io.cucumber.testng.*;
import org.openqa.selenium.*;
import org.testng.annotations.*;

import io.cucumber.testng.TestNGCucumberRunner;

@CucumberOptions(
        features = {"./src/test/resources/features/"}
        , glue = {"stepDefinitions"}
        , plugin = {"pretty:target/cucumber-reports/cucumber-pretty.txt",
        "html:target/cucumber-reports/raw-cucumber-html-report.html",
        "json:target/report.json",
        , monochrome = true
)
public class RunnerTest extends AbstractTestNGCucumberTests {

    private static TestNGCucumberRunner testNGCucumberRunner;

    @BeforeClass(alwaysRun = true)
    public void setUpClass() {
        testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());
    }

    @AfterClass(alwaysRun = true)
    public void tearDownClass() {
        testNGCucumberRunner.finish();
    }

    @Test(suiteName = "Suite", description = "Runs Cucumber Parallel Scenarios", dataProvider = "parallelScenarios")
    public void runParallelScenario(PickleWrapper pickleWrapper, FeatureWrapper featureWrapper) {
            testNGCucumberRunner.runScenario(pickleWrapper.getPickle());
         
    @DataProvider(parallel = true)
    public Object[][] parallelScenarios() {
        if (testNGCucumberRunner == null) {
            testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());
        }
        return testNGCucumberRunner.provideScenarios();
    }
}

还有 Suite.xml:

And the Suite.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="Test Suite" verbose="1" data-provider-thread-count="30">
    <test name="Scenario" verbose="1">
            <classes>
                <class name="runners.RunnerTest"/>
            </classes>
    </test>
</suite>

Pom.xml:

<?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">

    <parent>
        <groupId>com.client.tests</groupId>
        <artifactId>client-tests</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>

    <groupId>com.test.suite</groupId>
    <artifactId>test-suite</artifactId>
    <name>tests-suite</name>

    <dependencies>

        <!-- CUCUMBER DEPENDENCIES -->

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-core</artifactId>
            <version>6.2.1</version>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>6.2.1</version>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java8</artifactId>
            <version>6.2.1</version>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-testng</artifactId>
            <version>6.2.1</version>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>6.2.1</version>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>gherkin</artifactId>
            <version>5.1.0</version>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>gherkin3</artifactId>
            <version>3.1.2</version>
        </dependency>

        <!-- TESTNG DEPENDENCIES -->

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

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

        <dependency>
            <groupId>com.google.inject</groupId>
            <artifactId>guice</artifactId>
            <version>4.1.0</version>
        </dependency>

        <!-- OTHER DEPENDENCIES -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-configuration2</artifactId>
        </dependency>

      <dependency>
        <groupId>org.jetbrains</groupId>
        <artifactId>annotations</artifactId>
        <version>16.0.1</version>
        <scope>compile</scope>
      </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.codeborne</groupId>
            <artifactId>selenide</artifactId>
            <version>5.10.0</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.maven.surefire</groupId>
            <artifactId>surefire-testng</artifactId>
            <version>3.0.0-M4</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <suiteXmlFiles>
                        <reportsDirectory>target/TestNG-Report</reportsDirectory>
                        <suiteXmlFile>Suite.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>test-jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <profiles>
        <profile>
            <id>build</id>
            <build>
                <resources>
                    <resource>
                        <directory>src/test/resources</directory>
                        <includes>
                            <include>**/*</include>
                        </includes>
                    </resource>
                </resources>
            <plugins>
                <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>3.1.0</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>3.1.0</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                            <configuration>
                                <transformers>
                                    <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                        <mainClass>at.seresunit.lecturemanager_connector.App</mainClass>
                                    </transformer>
                                    <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                        <resource>META-INF/spring.handlers</resource>
                                    </transformer>
                                    <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                        <resource>META-INF/spring.schemas</resource>
                                    </transformer>
                                </transformers>
                                <filters>
                                    <filter>
                                        <artifact>*:*</artifact>
                                        <excludes>
                                            <exclude>META-INF/*.SF</exclude>
                                            <exclude>META-INF/*.DSA</exclude>
                                            <exclude>META-INF/*.RSA</exclude>
                                        </excludes>
                                    </filter>
                                </filters>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
            </build>
        </profile>
    </profiles>
</project>

所以基本上我使用 IntelliJ 执行 XML 套件,参数如下:

So basically I'm executing the XML suite with IntelliJ, with the following params:

VM options: -ea -Dcucumber.filter.tags="@tag"
Working Directory: $MODULE_WORKING_DIR$
And pointing the path of the XML/modules
Also using Listeners > Use default reporters

最后,测试正确执行,但没有包含TestNG文件的输出文件夹.

Finally, the test are correctly executed, but there is no output folder with TestNG files.

每当我尝试跑步时:mvn test -Dcucumber.filter.tags="@tag"

我没有执行任何操作,它显示以下内容:

I get nothing executed and it shows the following:

[INFO] --- maven-surefire-plugin:3.0.0-M5:test (default-test) @ client-tests ---
[INFO] Tests are skipped.

我希望在对当前设置进行最小更改的情况下生成输出文件.有人知道为什么没有生成它们,甚至调用 XML 套件并在运行器中使用所有 TestNG 注释吗?

I would like to have the Output files generated with minimal changes to the current setup. Does somebody have any clue why they are not being generated, even calling the XML suite and using all TestNG annotations in the runner?

提前致谢.

杰克逊.

推荐答案

Surefire 和 Failssafe 插件本身不会跳过你的测试.您要么在命令行中明确跳过它们,要么在父 POM 中跳过它们:

The Surefire and Failssafe plugin would not skip your tests by itself. Either you skipped them explicitely in the command line or you skipped them in the parent POM:

<parent>
    <groupId>com.client.tests</groupId>
    <artifactId>client-tests</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</parent>

不要在您的依赖项部分使用万无一失的工件.请删除它.

Do NOT use surefire artifacts in your dependencies section. Please remove it.

<dependency>
    <groupId>org.apache.maven.surefire</groupId>
    <artifactId>surefire-testng</artifactId>
    <version>3.0.0-M4</version>
</dependency>

并像这样在插件中使用依赖项:

And use the dependency within the plugin like this:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.0.0-M5</version>
            <configuration>
                <suiteXmlFiles>
                    <reportsDirectory>target/TestNG-Report</reportsDirectory>
                    <suiteXmlFile>Suite.xml</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>
           <dependencies>
               <dependency>
                   <groupId>org.apache.maven.surefire</groupId>
                   <artifactId>surefire-testng</artifactId>
                   <version>3.0.0-M5</version>
               </dependency>
           </dependencies>
        </plugin>

这篇关于带有黄瓜 v6 的 TestNGCucumberRunner 不使用并行 DataProvider 生成输出文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆