简体   繁体   中英

Specify test case not to run in parallel with TestNG runner in Spring using Cucumber

I've been able to configure the project to run test cases in parallel using a TestNG runner; however, there are a handful of scenarios that are not very thread safe. If these test cases were to run in parallel, they'd interfere with each other. Now there are a couple of ways I could make these scenarios thread safe, but I was wondering if there was a way to specify these Cucumber scenarios not to run in parallel.

Is there a specific tag I could configure to tag scenarios not to run in parallel? Specify certain feature files not to run in parallel? I believe I might have come across something like that for JUnit 5, but does this exist with TestNG?

Unlike JUnit 5, TestNG does not provide such fine-grained controls. At best you can create multiple runner classes with a different selection of features and different configurations for parallel/serial execution.

Another thing I just realized was I could make the number of threads an argument; with a default of 1 thread.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>${maven.surefire.version}</version>
    <configuration>
        <testFailureIgnore>true</testFailureIgnore>
                    <properties>
                        <property>
                            <name>dataproviderthreadcount</name>
                            <value>1</value>
                        </property>
                    </properties>
                    <includes>
                        <include>api.automation.tests.runners.TestNGRunnerTest</include>
                    </includes>
    </configuration>
</plugin>

I have one Jenkins build that has all the tests tagged with the same name to run in parallel with however many threads needed.

mvn clean test -Dcucumber.filter.tags="${CucumberFilterTag} and not @opentofix" -Dspring.profiles.active=${Environment} -Ddataproviderthreadcount=4

And in the other build, I have a very similar command (with a different tag) just without the added arguement; to use the default of just one thread. This will run all those tagged tests one at a time.

mvn clean test -Dcucumber.filter.tags="${CucumberFilterTag} and not @opentofix" -Dspring.profiles.active=${Environment}

Either way, the first answer still works, but just thought to add this possibility.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM