在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):trivago/cucable-plugin开源软件地址(OpenSource Url):https://github.com/trivago/cucable-plugin开源编程语言(OpenSource Language):Java 97.9%开源软件介绍(OpenSource Introduction):Run Cucumber Scenarios in Parallel with MavenNote:This project is feature-complete. Expect mostly bug fixes from this point on. For new projects, you should consider using Cucumber's native parallelization feature instead. Thanks to everyone using, testing and improving Cucable over the last years!
Cucable Maven PluginCucable is a Maven plugin for Cucumber scenarios that simplifies fine-grained and efficient parallel test runs. This plugin does the following:
Those generated runners and features can then be used with Maven Failsafe in order to parallelize test runs. This also works for non-english feature files! Cucumber 4Even though Cucumber 4 supports basic parallel runs, Cucable has more options that may be beneficial for your use case:
Cucumber 5
Repository Structure
ChangelogAll changes are documented in the full changelog. Maven dependency<dependency>
<groupId>com.trivago.rta</groupId>
<artifactId>cucable-plugin</artifactId>
<version>(check version on top of the page)</version>
</dependency> How it works
Template placeholders[CUCABLE:RUNNER]The If the generated runner runs only one "single scenario" feature, its name will be the same as the generated feature (e.g. In case the runner runs multiple "single scenario" features, its name will be auto-generated (e.g. [CUCABLE:FEATURE]The @CucumberOptions( features = {"target/parallel/features/[CUCABLE:FEATURE].feature"} ) Cucable will automatically detect the string containing the Custom template placeholders - [CUCABLE:CUSTOM:xxx]In some cases, you may need to set custom values that should be written to your template files. In this case, just add a block to your POM file:
These custom placeholders can be used anywhere in your template: import cucumber.api.CucumberOptions; @CucumberOptions( features = {"target/parallel/features/[CUCABLE:FEATURE].feature"}, plugin = {"json:target/cucumber-report/[CUCABLE:CUSTOM:foo].json"} ) public class [CUCABLE:RUNNER] { // [CUCABLE:CUSTOM:somename] } In this case the result would be import cucumber.api.CucumberOptions; @CucumberOptions( features = {"target/parallel/features/[CUCABLE:FEATURE].feature"}, plugin = {"json:target/cucumber-report/bar.json"} ) public class [CUCABLE:RUNNER] { // Any value } Note: The custom placeholder names are case sensitive! One runner per generated scenarioThis is the default mode of Cucable. Having multiple runners that run one "single scenario" feature each is best for parallelization with Maven Failsafe. One runner per group of generated scenariosIf you use the This means that it will only generate the specified number of runners (or features per runner) and distribute the generated features evenly among the runners. This is helpful if a group of scenarios should be executed during each forked run of your test framework. Note: If a runner runs only one feature, it automatically has the same name as the feature. Otherwise it will have a unique auto-generated name. Typical workflow
The following sections break down the above steps. 1. Generation of runners and features<plugin>
<groupId>com.trivago.rta</groupId>
<artifactId>cucable-plugin</artifactId>
<version>${cucable-plugin.version}</version>
<executions>
<execution>
<id>generate-test-resources</id>
<phase>generate-test-resources</phase>
<goals>
<goal>parallel</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- Required properties -->
<sourceRunnerTemplateFile>src/test/resources/parallel/cucable.template</sourceRunnerTemplateFile>
<sourceFeatures>src/test/resources/features</sourceFeatures>
<generatedFeatureDirectory>src/test/resources/parallel/features</generatedFeatureDirectory>
<generatedRunnerDirectory>src/test/java/parallel/runners</generatedRunnerDirectory>
<!-- Optional properties -->
<numberOfTestRuns>1</numberOfTestRuns>
<includeScenarioTags>@includeMe and @includeMeAsWell</includeScenarioTags>
<logLevel>compact</logLevel>
<desiredNumberOfRunners>2</desiredNumberOfRunners>
<!-- or <desiredNumberOfFeaturesPerRunner>5</desiredNumberOfRunners> -->
</configuration>
</plugin> Required ParameterssourceRunnerTemplateFileThe specified file will be used to generate runner classes for the generated feature file that can be run using Maven Failsafe. This can be either a text file or a Java class. The difference can be seen below: Using a java file as a runner templateIf you use a java file (e.g. src/test/java/some/template/CucableJavaTemplate.java), the [CUCABLE:FEATURE] placeholder as well as the class name will be substituted for the generated feature file name(s). The [CUCABLE:RUNNER] placeholder will be replaced by the runner class name. Additionally, the package declaration will be stripped. Example: package some.template; import cucumber.api.CucumberOptions; @CucumberOptions( features = {"target/parallel/features/[CUCABLE:FEATURE].feature"}, plugin = {"json:target/cucumber-report/[CUCABLE:RUNNER].json"} ) public class CucableJavaTemplate { } will turn into import cucumber.api.CucumberOptions; @CucumberOptions( features = {"target/parallel/features/MyFeature_scenario001_run001_IT.feature"}, plugin = {"json:target/cucumber-report/MyFeature_scenario001_run001_IT.json"} ) public class MyFeature_scenario001_run001_IT { } // Generated by Cucable from src/test/java/some/template/CucableJavaTemplate.java In case of a fixed number of runners that contain multiple scenarios (via import cucumber.api.junit.Cucumber; import cucumber.api.CucumberOptions; import org.junit.runner.RunWith; @RunWith(Cucumber.class) @CucumberOptions( features = {"target/parallel/features/Bookmarks_scenario001_run001_IT.feature", "target/parallel/features/Bookmarks_scenario003_run001_IT.feature"}, plugin = { "json:target/cucumber-report/CucableMultiRunner_1da810a2_c4c6_4edb_b078_d81329593950_IT.json", "com.trivago.trupi.plugin.TrupiCucumberPlugin" }, glue = {"com.trivago.trupi.glue"} ) public class CucableMultiRunner_1da810a2_c4c6_4edb_b078_d81329593950_IT { } // Generated by Cucable from src/test/java/some/template/CucableJavaTemplate.java Using a text file as a runner templateIf you use a text file (e.g. src/test/resources/cucable.template), all [CUCABLE:FEATURE] placeholder will be substituted for the generated feature file name(s). The [CUCABLE:RUNNER] placeholder will be replaced by the runner class name. sourceFeaturesThis property specifies the location of the features that Cucable should process. It must point to one of the following:
generatedFeatureDirectoryThe path where the generated Cucumber .feature files should be located (e.g. src/test/resources/parallel). Note: This directory should be located under a valid resource folder to be included as a test source by Maven. If you want to use a directory inside Maven's target folder, check this example. Caution: This directory will be wiped prior to the feature file generation! generatedRunnerDirectoryThe path where the generated runner classes should be located (e.g. src/test/java/parallel/runners). Note: This directory should be located under a valid source folder to be included as a test source by Maven. If you want to use a directory inside Maven's target folder, check this example. Caution: This directory will be wiped prior to the runner file generation! Optional ParametersnumberOfTestRunsOptional number of test runs. This can be used if specific scenarios should be run multiple times. If this options is not set, its default value is 1. For each test run, the whole set of features and runners is generated like this:
Note: Characters other than letters from A to Z, numbers and underscores will be stripped out of the feature file name. includeScenarioTags
Example: include scenarios that are tagged with @scenario1: <includeScenarioTags>@scenario1</includeScenarioTags> Example: include scenarios that are tagged with @scenario1 or @scenario2: <includeScenarioTags>@scenario1 or @scenario2</includeScenarioTags> Example: include scenarios that are tagged with @scenario1 and @scenario2: <includeScenarioTags>@scenario1 and @scenario2</includeScenarioTags> Example: include scenarios that are not tagged with @scenario1: <includeScenarioTags>not @scenario1</includeScenarioTags> Example: include scenarios that are not tagged with @scenario1 but tagged with scenario2 or scenario3: <includeScenarioTags>not @scenario1 and (@scenario2 or scenario3)</includeScenarioTags> parallelizationModeBy default, Cucable uses the Sometimes it may be desirable, to parallelize complete features. When setting the <parallelizationMode>features</parallelizationMode> Note: For this mode to work, logLevelBy default, Cucable logs all information including
This can be configured by passing the
desiredNumberOfRunnersIf you set this options, all generated features will be distributed to a fixed set of runner classes. This means that one runner can potentially run multiple features in sequence. If this option is not set, its default value is Note: This cannot be used together with desiredNumberOfFeaturesPerRunnerIf you set this option, all generated features will be distributed to a dynamic set of runner classes so that every runner contains a fixed number of generated features. This means that one runner can potentially run multiple features in sequence. If this option is not set, its default value is Note: This cannot be used together with scenarioNamesA comma separated list of strings matching a scenario name, either completely or partially. Please see <scenarioNames>
name1,
name2
</scenarioNames> 2 runner files will be generated. The first file will contain all the scenarios matching Note: This cannot be used together with Generating runners and features inside target directoryIt may be desirable for you to generate the Cucable features and runners in Maven's In order to achieve this, you can specify subdirectories under target ( After this step, use the build-helper-maven-plugin in your POM file in order to consider the generated runner classes test sources: <plugins>
<plugin>
<groupId>com.trivago.rta</groupId>
<artifactId>cucable-plugin</artifactId>
<version>${cucable.plugin.version}</version>
<executions>
<execution>
<id>generate-test-resources</id>
<phase>generate-test-resources</phase>
<goals>
<goal>parallel</goal>
</goals>
</execution>
</executions>
<configuration>
<sourceRunnerTemplateFile>path_to_template_file</sourceRunnerTemplateFile>
<sourceFeatures>path_to_features</sourceFeatures>
<generatedFeatureDirectory>${project.build.directory}/parallel/features</generatedFeatureDirectory>
<generatedRunnerDirectory>${project.build.directory}/parallel/runners</generatedRunnerDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${build.helper.plugin.version}</version>
<executions>
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
</execution>
</executions>
<configuration>
<sources>
<source>${project.build.directory}/parallel/runners</source>
</sources>
</configuration>
</plugin>
</plugins>
Complete ExampleBelow, you can see a full example of what Cucable does. Source feature fileThis is our source feature file. It contains a scenario and a scenario outline with two examples. MyFeature.feature
Runner template fileThis is the runner template file (in this example we use a text file) that is used to generate sin |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论