Skip to content

Commit

Permalink
Merge pull request #187 from trivago/no-runner-generation
Browse files Browse the repository at this point in the history
No runner generation option
  • Loading branch information
bischoffdev authored Dec 4, 2023
2 parents 4daf7d6 + d42e02e commit 7ff1c59
Show file tree
Hide file tree
Showing 14 changed files with 218 additions and 111 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

Back to [Readme](README.md).

## [1.11.0] - 2023-12-04

### Added

* New way to only generate features without runners by specifying `<desiredNumberOfRunners>0</desiredNumberOfRunners>`.

### Changed

* Default value of `<desiredNumberOfRunners>` was changed from `0` to `-1`:
* `-1` means that the number generated runners should be equal to the number generated scenarios.
* `0` means that no runners should be generated at all.
* Java 11 requirement

### Changed

* Updated dependencies

## [1.10.0] - 2023-06-27

### Added
Expand Down Expand Up @@ -330,6 +347,7 @@ Back to [Readme](README.md).

Initial project version on GitHub and Maven Central.

[1.11.0]: https://github.com/trivago/cucable-plugin/compare/1.9.0...1.10.0
[1.10.0]: https://github.com/trivago/cucable-plugin/compare/1.9.0...1.10.0
[1.9.0]: https://github.com/trivago/cucable-plugin/compare/1.8.0...1.9.0
[1.8.0]: https://github.com/trivago/cucable-plugin/compare/1.7.2...1.8.0
Expand Down
36 changes: 26 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,28 @@ _Run Cucumber Scenarios in Parallel with Maven_
- [Cucable Maven Plugin](#cucable-maven-plugin)
- [Cucumber 4](#cucumber-4)
- [Cucumber 5 and higher](#cucumber-5-and-higher)
- [JUnit 5](#junit-5)
- [Repository Structure](#repository-structure)
- [Changelog](#changelog)
- [Maven dependency](#maven-dependency)
- [How it works](#how-it-works)
- [Template placeholders](#template-placeholders)
- [Runner template placeholders](#runner-template-placeholders)
- [[CUCABLE:RUNNER]](#cucablerunner)
- [[CUCABLE:FEATURE]](#cucablefeature)
- [Custom template placeholders - [CUCABLE:CUSTOM:xxx]](#custom-template-placeholders---cucablecustomxxx)
- [One runner per generated scenario](#one-runner-per-generated-scenario)
- [One runner per group of generated scenarios](#one-runner-per-group-of-generated-scenarios)
- [No runners](#no-runners)
- [Typical workflow](#typical-workflow)
- [1. Generation of runners and features](#1-generation-of-runners-and-features)
- [Required Parameters](#required-parameters)
- [Parameters](#parameters)
- [sourceRunnerTemplateFile](#sourcerunnertemplatefile)
- [Using a java file as a runner template](#using-a-java-file-as-a-runner-template)
- [Using a text file as a runner template](#using-a-text-file-as-a-runner-template)
- [sourceFeatures](#sourcefeatures)
- [Combining different feature sources](#combining-different-feature-sources)
- [generatedFeatureDirectory](#generatedfeaturedirectory)
- [generatedRunnerDirectory](#generatedrunnerdirectory)
- [Optional Parameters](#optional-parameters)
- [numberOfTestRuns](#numberoftestruns)
- [includeScenarioTags](#includescenariotags)
- [parallelizationMode](#parallelizationmode)
Expand Down Expand Up @@ -86,6 +87,10 @@ Even though Cucumber 4 supports basic parallel runs, Cucable has more options th

* Cucumber starting with version 5 (using testng or junit 5) can natively run features and scenarios in parallel. Cucable __can__ be used but does not __have__ to be.

## JUnit 5

When using the JUnit 5 platform, Cucable can still help parallelize scenarios more fine-grained and with more options than the standard JUnit and Cucumber properties.

## Repository Structure

* [plugin-code](plugin-code) contains the full plugin source code.
Expand All @@ -111,9 +116,12 @@ All changes are documented in the [full changelog](CHANGELOG.md).
* Each generated feature file includes a single scenario
* After this, the runner classes for those generated features are generated based on a provided template file, either
* one runner per generated "single scenario" feature file or
* one runner per group of "single scenario" feature files
* one runner per group of "single scenario" feature files or
* no runners at all (not needed if your tests are run as unit tests with JUnit 5 or TestNG)

## Runner template placeholders

## Template placeholders
__Note:__ If you don't need runner classes to be generated, you can skip this section.

### [CUCABLE:RUNNER]

Expand Down Expand Up @@ -177,7 +185,7 @@ public class [CUCABLE:RUNNER] {
}
</pre>

**Note:** The custom placeholder names are case sensitive!
**Note:** The custom placeholder names are case-sensitive!

## One runner per generated scenario

Expand All @@ -195,6 +203,12 @@ This means that it will only generate the specified number of runners (or featur

![Multi feature runner generation](documentation/img/cucable_flow_multi_runner.png)

## No runners

If you set `desiredNumberOfRunners` to `0`, this means that Cucable will not generate runner classes at all. In this case, you do not need to set these properties:
* `sourceRunnerTemplateFile` (as you do not need a template file)
* `generatedRunnerDirectory` (as no runners will be generated)

# Typical workflow

1. Generation of runners and features
Expand Down Expand Up @@ -237,10 +251,12 @@ The following sections break down the above steps.
</plugin>
```

### Required Parameters
### Parameters

#### sourceRunnerTemplateFile

__Note:__ This is only needed, when you want to generate runner classes!

The specified file will be used to generate runner classes for the generated feature file that can be run using [Maven Failsafe](http://maven.apache.org/surefire/maven-failsafe-plugin/).

This can be either a text file or a Java class. The difference can be seen below:
Expand Down Expand Up @@ -362,15 +378,15 @@ If you want to use a directory inside Maven's target folder, [check this example

#### generatedRunnerDirectory

__Note:__ This is only needed, when you want to generate runner classes!

The 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](#generating-runners-and-features-inside-target-directory).

**Caution:** This directory will be wiped prior to the runner file generation!

### Optional Parameters

#### numberOfTestRuns

Optional number of test runs. This can be used if specific scenarios should be run multiple times.
Expand Down Expand Up @@ -449,7 +465,7 @@ This can be configured by passing the `logLevel` property:

If 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 `0` which basically means "Generate a dedicated runner for every generated feature".
If this option is not set, its default value is `-1` which basically means "Generate a dedicated runner for every generated feature".

__Note:__ This cannot be used together with `desiredNumberOfFeaturesPerRunner`!

Expand Down
25 changes: 15 additions & 10 deletions example-project/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@

<groupId>com.trivago.rta</groupId>
<artifactId>cucable-test-project</artifactId>
<version>1.10.0</version>
<version>1.11.0</version>
<packaging>jar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.failsafe.plugin.version>3.0.0-M3</maven.failsafe.plugin.version>
<maven.build.helper.plugin.version>3.0.0</maven.build.helper.plugin.version>
<cucumber.version>6.9.0</cucumber.version>
<maven.compiler.plugin.version>3.7.0</maven.compiler.plugin.version>
<maven.failsafe.plugin.version>3.1.2</maven.failsafe.plugin.version>
<maven.build.helper.plugin.version>3.4.0</maven.build.helper.plugin.version>
<cucumber.version>7.11.1</cucumber.version>
<maven.compiler.plugin.version>3.11.0</maven.compiler.plugin.version>
<maven.jar.plugin.version>3.1.2</maven.jar.plugin.version>

<generated.runner.directory>${project.build.directory}/parallel/runners</generated.runner.directory>
<generated.feature.directory>${project.build.directory}/parallel/features</generated.feature.directory>
<maven-resources-plugin.version>3.3.1</maven-resources-plugin.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -53,7 +54,7 @@
</executions>
<configuration>
<!-- This can be either a Java class file or a text based template -->
<sourceRunnerTemplateFile>src/test/java/some/template/CucableJavaTemplate.java
<sourceRunnerTemplateFile>src/test/java/some/template/CucableTemplate.java
</sourceRunnerTemplateFile>
<!--<sourceRunnerTemplateFile>src/test/resources/cucable.template</sourceRunnerTemplateFile>-->

Expand All @@ -73,7 +74,7 @@
<!-- <sourceFeatures>@src/test/resources/cucumber-feature-list.txt</sourceFeatures> -->

<!-- process a folder that hosts text files containing paths to features and line numbers (as it is written by the Cucumber rerun formatter) -->
<!-- <sourceFeatures>@src/test/resources</sourceFeatures>-->
<!-- <sourceFeatures>@src/test/resources</sourceFeatures> -->

<!-- process a specific feature file and specific line numbers in the given directory -->
<sourceFeatures>src/test/resources/features/testfeature/MyTest1.feature:8:19</sourceFeatures>
Expand Down Expand Up @@ -104,7 +105,7 @@

<!-- optional: generate a fixed number of runners and distribute all features round-robin.
This can only be used if desiredNumberOfFeaturesPerRunner is NOT used! -->
<!--<desiredNumberOfRunners>2</desiredNumberOfRunners>-->
<!-- <desiredNumberOfRunners>0</desiredNumberOfRunners> -->

<!-- optional: distribute a fixed number features per runner round-robin.
This can only be used if desiredNumberOfRunners is NOT used! -->
Expand Down Expand Up @@ -154,13 +155,17 @@
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven-resources-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>8</source>
<target>8</target>
<release>11</release>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
@RunWith(Cucumber.class)
@CucumberOptions(
glue = "steps",
strict = true,
features = {"target/parallel/features/[CUCABLE:FEATURE].feature"},
plugin = {"json:target/cucumber-report/[CUCABLE:RUNNER].json"}
)
public class CucableJavaTemplate {
public class CucableTemplate {
// [CUCABLE:CUSTOM:comment]
}
2 changes: 1 addition & 1 deletion example-project/src/test/resources/cucable.template
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ import org.junit.runner.RunWith;
features = {"target/parallel/features/[CUCABLE:FEATURE].feature"},
plugin = {"json:target/cucumber-report/[CUCABLE:RUNNER].json"}
)
public class CucableJavaTemplate {
public class CucableTemplate {
// [CUCABLE:CUSTOM:comment]
}
14 changes: 11 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
build-and-test:
help: ## Show this help.
@grep -hE '^[A-Za-z0-9_ \-]*?:.*##.*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: help

build-and-test: ## Build the plugin and run demo tests
mvn clean install
mvn verify -f=examples/maven-example
open examples/maven-example/target/cluecumber-report/index.html
mvn verify -f=examples-project/pom.xml -ntp
open example-project/target/cluecumber-report/index.html

show-versions: ## Show most recent dependency versions
mvn versions:display-dependency-updates -ntp -f=plugin-code/pom.xml
.PHONY: show-versions
35 changes: 19 additions & 16 deletions plugin-code/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.trivago.rta</groupId>
<artifactId>cucable-plugin</artifactId>
<version>1.10.0</version>
<version>1.11.0</version>
<url>https://github.com/trivago/cucable-plugin</url>

<name>Cucable Maven Plugin</name>
Expand All @@ -17,14 +17,14 @@

<organization>
<name>trivago N.V.</name>
<url>http://www.trivago.de</url>
<url>https://www.trivago.com</url>
</organization>

<developers>
<developer>
<name>Benjamin Bischoff</name>
<organization>trivago N.V.</organization>
<organizationUrl>http://www.trivago.de</organizationUrl>
<organizationUrl>https://www.trivago.com</organizationUrl>
<roles>
<role>Test Automation Engineer</role>
<role>Knowledge Lead Test Automation</role>
Expand Down Expand Up @@ -70,21 +70,20 @@
<maven.jar.plugin.version>3.3.0</maven.jar.plugin.version>
<maven.compiler.plugin.version>3.11.0</maven.compiler.plugin.version>
<maven.plugin.testing.harness.version>3.3.0</maven.plugin.testing.harness.version>
<jacoco.maven.plugin>0.8.10</jacoco.maven.plugin>
<plexus.component.annotations.version>2.1.0</plexus.component.annotations.version>
<maven.plugin.annotations.version>3.6.0</maven.plugin.annotations.version>
<jacoco.maven.plugin>0.8.11</jacoco.maven.plugin>
<plexus.component.annotations.version>2.1.1</plexus.component.annotations.version>
<maven.plugin.annotations.version>3.10.2</maven.plugin.annotations.version>
<maven.source.plugin.version>3.3.0</maven.source.plugin.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.release>8</maven.compiler.release>
<gherkin.version>5.2.0</gherkin.version>
<tag.expressions.version>5.0.1</tag.expressions.version>
<apache.commons.version>3.12.0</apache.commons.version>
<tag.expressions.version>6.0.0</tag.expressions.version>
<apache.commons.version>3.14.0</apache.commons.version>

<mockito.version>3.6.28</mockito.version>
<junit5.vintage.version>5.7.0</junit5.vintage.version>
<mockito.version>4.11.0</mockito.version>
<junit5.vintage.version>5.10.1</junit5.vintage.version>
<openpojo.version>0.9.1</openpojo.version>
<plexus-utils.version>3.5.0</plexus-utils.version>
<plexus-utils.version>4.0.0</plexus-utils.version>
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
<maven-resources-plugin.version>3.3.1</maven-resources-plugin.version>
</properties>

<profiles>
Expand Down Expand Up @@ -124,13 +123,17 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven-resources-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>8</source>
<target>8</target>
<release>11</release>
</configuration>
</plugin>
<plugin>
Expand Down
6 changes: 3 additions & 3 deletions plugin-code/src/main/java/com/trivago/CucablePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@
/**
* The complete path to the runner template file.
*/
@Parameter(property = "parallel.sourceRunnerTemplateFile", required = true)
@Parameter(property = "parallel.sourceRunnerTemplateFile", required = false, defaultValue = "")
private String sourceRunnerTemplateFile;

/**
* The path where the generated runner classes should be created.
*/
@Parameter(property = "parallel.generatedRunnerDirectory", required = true)
@Parameter(property = "parallel.generatedRunnerDirectory", required = false, defaultValue = "")
private String generatedRunnerDirectory;

/**
Expand Down Expand Up @@ -90,7 +90,7 @@
/**
* Optional desired number of test runners that each run multiple features in sequence.
*/
@Parameter(property = "parallel.desiredNumberOfRunners", defaultValue = "0")
@Parameter(property = "parallel.desiredNumberOfRunners", defaultValue = "-1")
private int desiredNumberOfRunners;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,10 @@ private int generateRunnerClassesWithDesiredNumberOfRunners(final List<String> g
int targetRunnerNumber = numberOfDesiredRunners;
List<String> scenarioNames = propertyManager.getScenarioNames();

if (targetRunnerNumber == 0) {
if (targetRunnerNumber == -1) {
targetRunnerNumber = generatedFeatureNames.size();
} else if (targetRunnerNumber == 0) {
return 0;
}

List<List<String>> generatedFeatureNamesPerRunner = new ArrayList<>(targetRunnerNumber);
Expand Down Expand Up @@ -367,7 +369,7 @@ private int generateRunnerClassesWithDesiredNumberOfRunners(final List<String> g

int runnerFileCounter = 0;
for (List<String> generatedFeatureNamesForSingleRunner : generatedFeatureNamesPerRunner) {
if (generatedFeatureNamesForSingleRunner.size() > 0) {
if (!generatedFeatureNamesForSingleRunner.isEmpty()) {
generateRunnerClass(generatedFeatureNamesForSingleRunner);
runnerFileCounter++;
}
Expand Down
Loading

0 comments on commit 7ff1c59

Please sign in to comment.