Skip to content

Commit

Permalink
Merge pull request temyers#13 from tommywo/master
Browse files Browse the repository at this point in the history
Added support for TestNG
  • Loading branch information
temyers committed Mar 15, 2016
2 parents 590026b + 60d6bbe commit 5732443
Show file tree
Hide file tree
Showing 34 changed files with 765 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<groupId>com.github.temyers</groupId>
<artifactId>cucumber-jvm-parallel-plugin</artifactId>
<version>1.0.2-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>

<name>cucumber-jvm-parallel-plugin Maven Plugin</name>
Expand Down
24 changes: 15 additions & 9 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
cucumber-jvm-parallel-plugin ![CI status](https://travis-ci.org/temyers/cucumber-jvm-parallel-plugin.svg?branch=master)
============================

A common approach for running Cucumber features in parallel is to create a suite of Cucumber JUnit runners, one for each suite of tests you wish to run in parallel. For maximum parallelism, there should be a runner per feature file.
A common approach for running Cucumber features in parallel is to create a suite of Cucumber runners, one for each suite of tests you wish to run in parallel. For maximum parallelism, there should be a runner per feature file.

This is a pain to maintain and not very DRY.

This is where the cucumber-jvm-parallel-plugin comes in. This plugin automatically generates a Cucumber JUnit runner for each feature file found in your project.
This is where the cucumber-jvm-parallel-plugin comes in. This plugin automatically generates a Cucumber JUnit or TestNG runner for each feature file found in your project.

Usage
-----
Expand All @@ -16,7 +16,7 @@ Add the following to your POM file:
<plugin>
<groupId>com.github.temyers</groupId>
<artifactId>cucumber-jvm-parallel-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
<executions>
<execution>
<id>generateRunners</id>
Expand All @@ -29,7 +29,7 @@ Add the following to your POM file:
<!-- comma separated list of package names to scan for glue code -->
<glue>foo, bar</glue>
<!-- These are the default values -->
<!-- Where to output the generated Junit tests -->
<!-- Where to output the generated tests -->
<outputDirectory>${project.build.directory}/generated-test-sources/cucumber</outputDirectory>
<!-- The diectory containing your feature files. -->
<featuresDirectory>src/test/resources/features/</featuresDirectory>
Expand All @@ -46,6 +46,8 @@ Add the following to your POM file:
<!-- If set to true, only feature files containing the required tags shall be generated. -->
<!-- Excluded tags (~@notMe) are ignored. -->
<filterFeaturesByTags>false</filterFeaturesByTags>
<!-- Generate TestNG runners instead of JUnit ones. -->
<useTestNG>false</useTestNG>
</configuration>
</execution>
</executions>
Expand All @@ -56,11 +58,11 @@ If `cucumber.options` VM argument is specified as per the [Cucumber CLI options]

Where glue is a comma separated list of package names to use for the Cucumber Glue.

The plugin will search `featuresDirectory` for `*.feature` files and generate a JUnit test for each one.
The plugin will search `featuresDirectory` for `*.feature` files and generate a JUnit test for each one. If you prefer to generate TestNG tests, set `useTestNG` to true

The Java source is generated in `outputDirectory`, and will have the pattern `ParallelXXIT.java`, where `XX` is a one up counter.

Each JUnit test is configured to output the results to a separate output file under `target/cucumber-parallel`
Each runner is configured to output the results to a separate output file under `target/cucumber-parallel`

FAQ
===
Expand All @@ -69,6 +71,10 @@ A. The plugin is considered feature complete. If you feel there is something mi

Changelog
=========
1.1.0
-----
* pr#13 - Added support for generating TestNG runners.

1.0.1
-----
* issue#10 - compilation error on Windows.
Expand All @@ -80,9 +86,9 @@ Contributing

To contribute:

* Create an integration test to demonstrate the behaviour under `src/it/`. For example, to add support for multiple output formats:
* Create src/it/multiple-format
* copy the contents of the src/it/simple-it directory and update the pom/src as appropriate to demonstrate the configuration. Update the verify.groovy to implement the test for your feature.
* Create an integration test to demonstrate the behaviour under `src/it/`. For example, to add support for multiple output formats for junit runners:
* Create src/it/junit/multiple-format
* copy the contents of the src/it/junit/simple-it directory and update the pom/src as appropriate to demonstrate the configuration. Update the verify.groovy to implement the test for your feature.
* Run `mvn clean install -Prun-its` to run the integration tests.
* Implement the feature
* When all tests are passing, submit a pull request.
Expand Down
55 changes: 55 additions & 0 deletions src/it/testng/filter-by-tag/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?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">
<modelVersion>4.0.0</modelVersion>

<groupId>com.github.timm-permeance.it</groupId>
<artifactId>simple-it</artifactId>
<version>1.0-SNAPSHOT</version>

<description>A simple IT verifying the basic use case.</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<cucumber.version>1.1.8</cucumber.version>
</properties>

<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-testng</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>generateRunners</id>
<phase>validate</phase>
<goals>
<goal>generateRunners</goal>
</goals>
<configuration>
<glue>foo, bar</glue>
<!-- Only 1 feature contains this tag -->
<tags>"@feature1"</tags>
<filterFeaturesByTags>true</filterFeaturesByTags>
<useTestNG>true</useTestNG>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@feature1
Feature: Feature1

Scenario: Matching tags are included
Then this feature should should be included
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@feature2
Feature: Feature2

Scenario: Non Matching tags are excluded
Then this feature should should be excluded
21 changes: 21 additions & 0 deletions src/it/testng/filter-by-tag/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import org.junit.Assert;
import static org.hamcrest.Matchers.equalToIgnoringWhiteSpace;

File suite01 = new File( basedir, "target/generated-test-sources/cucumber/Parallel01IT.java" );
File suite02 = new File( basedir, "target/generated-test-sources/cucumber/Parallel02IT.java" );

assert suite01.isFile()
// Only one file should be created
assert !suite02.isFile()

String expected01=
"""import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;
@CucumberOptions(strict = true, features = {"classpath:features/feature1.feature"}, format = {"json:target/cucumber-parallel/1.json",
"pretty"}, monochrome = false, tags = {"@feature1"}, glue = { "foo", "bar" })
public class Parallel01IT extends AbstractTestNGCucumberTests {
}"""

Assert.assertThat(suite01.text, equalToIgnoringWhiteSpace(expected01))

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?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">
<modelVersion>4.0.0</modelVersion>

<groupId>com.github.timm-permeance.it</groupId>
<artifactId>simple-it</artifactId>
<version>1.0-SNAPSHOT</version>

<description>A simple IT verifying the basic use case.</description>

<properties>
<cucumber.options>--format json</cucumber.options>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<cucumber.version>1.1.8</cucumber.version>
</properties>

<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-testng</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>generateRunners</id>
<phase>validate</phase>
<goals>
<goal>generateRunners</goal>
</goals>
<configuration>
<glue>foo, bar</glue>
<!-- Only 1 feature contains this tag -->
<tags>"@feature1"</tags>
<filterFeaturesByTags>true</filterFeaturesByTags>
<useTestNG>true</useTestNG>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@feature1
Feature: Feature1

Scenario: Matching tags are included
Then this feature should should be included
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@feature2
Feature: Feature2

Scenario: Non-matching tags are excluded
Then this feature should should be excluded
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import org.junit.Assert;
import static org.hamcrest.Matchers.equalToIgnoringWhiteSpace;

File suite01 = new File( basedir, "target/generated-test-sources/cucumber/Parallel01IT.java" );
File suite02 = new File( basedir, "target/generated-test-sources/cucumber/Parallel02IT.java" );

assert suite01.isFile()
// Only one file should be created
assert !suite02.isFile()

String expected01=
"""import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;
@CucumberOptions(strict = true, features = {"classpath:features/feature1.feature"}, format = {"json:target/cucumber-parallel/1.json",
"pretty"}, monochrome = false, tags = {"@feature1"}, glue = { "foo", "bar" })
public class Parallel01IT extends AbstractTestNGCucumberTests {
}"""

Assert.assertThat(suite01.text, equalToIgnoringWhiteSpace(expected01))
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?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">
<modelVersion>4.0.0</modelVersion>

<groupId>com.github.timm-permeance.it</groupId>
<artifactId>simple-it</artifactId>
<version>1.0-SNAPSHOT</version>

<description>A simple IT verifying the basic use case.</description>

<properties>
<cucumber.options>--tags @override</cucumber.options>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<cucumber.version>1.1.8</cucumber.version>
</properties>

<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-testng</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>generateRunners</id>
<phase>validate</phase>
<goals>
<goal>generateRunners</goal>
</goals>
<configuration>
<glue>foo, bar</glue>
<!-- Only 1 feature contains this tag -->
<tags>"@feature1"</tags>
<filterFeaturesByTags>true</filterFeaturesByTags>
<useTestNG>true</useTestNG>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@feature1 @override
Feature: Feature1

Scenario: Matching override tags are included
Then this feature should be included
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@feature2 @override
Feature: Feature2

Scenario: Matching override tags are included
Then this feature should be included
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@feature3
Feature: Feature3

Scenario: Non-matching override tags are excluded
Then this feature should be excluded
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import org.junit.Assert;
import static org.hamcrest.Matchers.equalToIgnoringWhiteSpace;

File suite01 = new File( basedir, "target/generated-test-sources/cucumber/Parallel01IT.java" );
File suite02 = new File( basedir, "target/generated-test-sources/cucumber/Parallel02IT.java" );
File suite03 = new File( basedir, "target/generated-test-sources/cucumber/Parallel03IT.java" );

assert suite01.isFile()
assert suite02.isFile()
// Only two files should be created
assert !suite03.isFile()

String expected01=
"""import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;
@CucumberOptions(strict = true, features = {"classpath:features/feature1.feature"}, format = {"json:target/cucumber-parallel/1.json",
"pretty"}, monochrome = false, tags = {"@override"}, glue = { "foo", "bar" })
public class Parallel01IT extends AbstractTestNGCucumberTests {
}"""

Assert.assertThat(suite01.text, equalToIgnoringWhiteSpace(expected01))

String expected02=
"""import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;
@CucumberOptions(strict = true, features = {"classpath:features/feature2.feature"}, format = {"json:target/cucumber-parallel/2.json",
"pretty"}, monochrome = false, tags = {"@override"}, glue = { "foo", "bar" })
public class Parallel02IT extends AbstractTestNGCucumberTests {
}"""

// Depending on the OS, listFiles can list files in different order. The actual order of files isn't necessary

if(suite01.text.contains("feature1") ){
Assert.assertThat(suite01.text, equalToIgnoringWhiteSpace(expected01))
Assert.assertThat(suite02.text, equalToIgnoringWhiteSpace(expected02))
}else{
Assert.assertThat(suite02.text, equalToIgnoringWhiteSpace(expected01))
Assert.assertThat(suite01.text, equalToIgnoringWhiteSpace(expected02))
}
Loading

0 comments on commit 5732443

Please sign in to comment.