Skip to content

Commit

Permalink
Merge pull request #155 from trivago/cucumber-text-file-support
Browse files Browse the repository at this point in the history
Cucumber text file support
  • Loading branch information
Benjamin Bischoff authored Mar 30, 2020
2 parents 75eb295 + e0e0bd8 commit 0035ee1
Show file tree
Hide file tree
Showing 31 changed files with 159 additions and 77 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

Back to [Readme](README.md).

## [1.7.0] - 2020-03-30

### Added

* Support for Cucumber feature text files

### Changed

* Various dependency and documentation updates

## [1.6.0] - 2019-12-10

### Changed
Expand Down Expand Up @@ -282,6 +292,7 @@ Back to [Readme](README.md).

Initial project version on GitHub and Maven Central.

[1.7.0]: https://github.com/trivago/cucable-plugin/compare/1.6.0...1.7.0
[1.6.0]: https://github.com/trivago/cucable-plugin/compare/1.5.3...1.6.0
[1.5.3]: https://github.com/trivago/cucable-plugin/compare/1.5.2...1.5.3
[1.5.2]: https://github.com/trivago/cucable-plugin/compare/1.5.1...1.5.2
Expand Down
30 changes: 25 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

### Note:

This project is feature-complete. Expect only bug fixes at this time.
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!
Expand Down Expand Up @@ -326,10 +326,30 @@ If you use a text file (e.g. _src/test/resources/cucable.template_), all **[CUCA

#### sourceFeatures

This can specify
* the root path of your __existing__ [Cucumber](https://cucumber.io) _.feature_ files (e.g. ```src/test/resources/features```)
* the path to a specific __existing__ [Cucumber](https://cucumber.io) _.feature_ file (e.g. ```src/test/resources/features/MyFeature.feature```)
* the path to a specific __existing__ [Cucumber](https://cucumber.io) _.feature_ file including line numbers of specific scenarios/scenario outlines inside this file (e.g. ```src/test/resources/features/MyFeature.feature:12:19``` would only convert the scenarios starting at line _12_ and _19_ inside _MyFeature.feature_)
This property specifies the location of the features that Cucable should process. It must point to one of the following:

* the root path of your __existing__ [Cucumber](https://cucumber.io) _.feature_ files, e.g.
`src/test/resources/features`
* the path to a specific __existing__ [Cucumber](https://cucumber.io) _.feature_ file, e.g.
`src/test/resources/features/MyFeature.feature`
* the path to a specific __existing__ [Cucumber](https://cucumber.io) _.feature_ file with optional line numbers of specific scenarios e.g.
`src/test/resources/features/MyFeature.feature:12:19`
* comma separated paths to specific __existing__ [Cucumber](https://cucumber.io) _.feature_ file(s) with optional line numbers or feature directories e.g.
```
src/test/resources/features/MyFeature.feature:12:19, src/test/resources/features/MyOther.feature, src/test/some/other/feature/directory
```
* the path to a [Cucumber](https://cucumber.io) text file containing the path to a feature including line number(s) per line (as written by the [Cucumber rerun reporter plugin](https://cucumber.io/docs/cucumber/reporting/?sbsearch=rerun#built-in-reporter-plugins), e.g.
```
@src/test/resources/rerun.txt
```

__Note:__ The path to a text file has to start with an `@` character!

The file contents can look like this:
```
file:///pathToProject/resources/features/feature1.feature:12
file:///pathToProject/resources/features/feature4.feature:6
```

**Note:** From Cucable 1.4.0 onwards it is possible to specify a combination as a comma separated list:

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

<groupId>com.trivago.rta</groupId>
<artifactId>cucable-test-project</artifactId>
<version>1.6.0</version>
<version>1.7.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>4.5.4</cucumber.version>
<cucumber.version>5.5.0</cucumber.version>
<maven.compiler.plugin.version>3.7.0</maven.compiler.plugin.version>
<maven.jar.plugin.version>3.1.2</maven.jar.plugin.version>

Expand Down Expand Up @@ -69,6 +69,9 @@
<!--src/test/resources/features/testfeature/MyTest8.feature-->
<!--</sourceFeatures>-->

<!-- process a text file containing paths to features and line numbers (as it is written by the Cucumber rerun formatter) -->
<!-- <sourceFeatures>@src/test/resources/cucumber-feature-list.txt</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
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package some.template;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(
glue = "steps",
strict = true,
features = {"target/parallel/features/[CUCABLE:FEATURE].feature"},
plugin = {"json:target/cucumber-report/[CUCABLE:RUNNER].json"}
)
Expand Down
26 changes: 14 additions & 12 deletions example-project/src/test/java/steps/ExampleSteps.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package steps;

import cucumber.api.java.en.And;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import cucumber.api.java.no.Gitt;
import cucumber.api.java.no.Og;
import cucumber.api.java.ro.Atunci;
import cucumber.api.java.ro.Cand;
import cucumber.api.java.ro.Datefiind;
import io.cucumber.datatable.DataTable;

import io.cucumber.docstring.DocString;
import io.cucumber.java.en.And;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import io.cucumber.java.no.Gitt;
import io.cucumber.java.no.Og;
import io.cucumber.java.ro.Atunci;
import io.cucumber.java.ro.Cand;
import io.cucumber.java.ro.Datefiind;

@SuppressWarnings("unused")
public class ExampleSteps {
@Given("^this is a given step$")
public void thisIsAGivenStep() {
Expand Down Expand Up @@ -49,11 +51,11 @@ public void thisIsABackgroundStep() {
}

@Given("^this is a given step with a docstring$")
public void thisIsAGivenStepWithADocstring(DataTable docString) {
public void thisIsAGivenStepWithADocstring(DocString docString) {
}

@Then("^I do something with a docstring$")
public void iDoSomethingWithADocstring(DataTable docString) {
public void iDoSomethingWithADocstring(DocString docString) {
}

@Gitt("^for å unngå at firmaet går konkurs$")
Expand Down
6 changes: 4 additions & 2 deletions example-project/src/test/resources/cucable.template
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import cucumber.api.CucumberOptions;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;

@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 [CUCABLE:RUNNER] {
public class CucableJavaTemplate {
// [CUCABLE:CUSTOM:comment]
}
3 changes: 3 additions & 0 deletions example-project/src/test/resources/cucumber-feature-list.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
src/test/resources/features/testfeature/MyTest1.feature:12
src/test/resources/features/testfeature/MyTest1.feature:19
src/test/resources/features/testfeature/MyTest4.feature:5
16 changes: 8 additions & 8 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.6.0</version>
<version>1.7.0</version>
<url>https://github.com/trivago/cucable-plugin</url>

<name>Cucable Maven Plugin</name>
Expand Down Expand Up @@ -63,25 +63,25 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<maven.version>3.6.1</maven.version>
<maven.version>3.6.3</maven.version>
<maven.gpg.plugin.version>1.6</maven.gpg.plugin.version>
<nexus.staging.maven.plugin.version>1.6.8</nexus.staging.maven.plugin.version>
<maven.plugin.plugin.version>3.5.1</maven.plugin.plugin.version>
<maven.jar.plugin.version>3.0.2</maven.jar.plugin.version>
<maven.compiler.plugin.version>3.7.0</maven.compiler.plugin.version>
<maven.plugin.testing.harness.version>3.3.0</maven.plugin.testing.harness.version>
<jacoco.maven.plugin>0.8.4</jacoco.maven.plugin>
<plexus.component.annotations.version>2.0.0</plexus.component.annotations.version>
<plexus.component.annotations.version>2.1.0</plexus.component.annotations.version>
<maven.plugin.annotations.version>3.6.0</maven.plugin.annotations.version>
<maven.source.plugin.version>3.0.1</maven.source.plugin.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<gherkin.version>5.1.0</gherkin.version>
<tag.expressions.version>2.0.2</tag.expressions.version>
<apache.commons.version>3.9</apache.commons.version>
<gherkin.version>5.2.0</gherkin.version>
<tag.expressions.version>2.0.4</tag.expressions.version>
<apache.commons.version>3.10</apache.commons.version>

<mockito.version>3.2.0</mockito.version>
<junit5.vintage.version>5.6.0-M1</junit5.vintage.version>
<mockito.version>3.3.3</mockito.version>
<junit5.vintage.version>5.6.1</junit5.vintage.version>
<openpojo.version>0.8.13</openpojo.version>
</properties>

Expand Down
10 changes: 5 additions & 5 deletions plugin-code/src/main/java/com/trivago/CucablePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
/**
* The main plugin class.
*/
@SuppressWarnings("FieldCanBeLocal")
@SuppressWarnings("unused")
@Mojo(name = "parallel")
final class
CucablePlugin extends AbstractMojo {
Expand All @@ -44,25 +44,25 @@
/**
* The complete path to the runner template file.
*/
@Parameter(property = "parallel.sourceRunnerTemplateFile", required = true, defaultValue = "")
@Parameter(property = "parallel.sourceRunnerTemplateFile", required = true)
private String sourceRunnerTemplateFile;

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

/**
* The path to .feature files or a concrete single feature file.
*/
@Parameter(property = "parallel.sourceFeatures", required = true, defaultValue = "")
@Parameter(property = "parallel.sourceFeatures", required = true)
private String sourceFeatures;

/**
* The path where the generated .feature files should be created.
*/
@Parameter(property = "parallel.generatedFeatureDirectory", required = true, defaultValue = "")
@Parameter(property = "parallel.generatedFeatureDirectory", required = true)
private String generatedFeatureDirectory;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class FeatureFileConverter {
private final FeatureFileContentRenderer featureFileContentRenderer;
private final RunnerFileContentRenderer runnerFileContentRenderer;
private final FileIO fileIO;
private FileSystemManager fileSystemManager;
private final FileSystemManager fileSystemManager;
private final CucableLogger logger;

// Holds the current number of single features per feature key
Expand Down Expand Up @@ -107,6 +107,9 @@ public void generateParallelizableFeatures(

for (CucableFeature cucableFeature : cucableFeatures) {
List<Path> paths = fileSystemManager.getPathsFromCucableFeature(cucableFeature);
if (paths.size() == 0) {
logger.warn("No features and runners could be created. Please check your properties!");
}
for (Path path : paths) {
List<String> generatedFeatureFilePaths = generateParallelizableFeatures(path, cucableFeature.getLineNumbers());
allGeneratedFeaturePaths.addAll(generatedFeatureFilePaths);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ public FileSystemManager(PropertyManager propertyManager) {
*/
public List<Path> getPathsFromCucableFeature(final CucableFeature cucableFeature) throws CucablePluginException {

if (cucableFeature == null){
if (cucableFeature == null) {
return Collections.emptyList();
}

String sourceFeatures = cucableFeature.getName();
File sourceFeaturesFile = new File(cucableFeature.getName());
String sourceFeatures = cucableFeature.getName().
replace("file://", "");

File sourceFeaturesFile = new File(sourceFeatures);
// Check if the property value is a single file or a directory
if (sourceFeaturesFile.isFile() && sourceFeatures.endsWith(FEATURE_FILE_EXTENSION)) {
return Collections.singletonList(Paths.get(sourceFeatures));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.Arrays;
import java.util.List;

@Singleton
class GherkinTranslations {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
package com.trivago.properties;

import com.trivago.exceptions.CucablePluginException;
import com.trivago.exceptions.filesystem.MissingFileException;
import com.trivago.exceptions.properties.WrongOrMissingPropertiesException;
import com.trivago.files.FileIO;
import com.trivago.logging.CucableLogger;
import com.trivago.logging.CucableLogger.CucableLogLevel;
import com.trivago.logging.Language;
Expand All @@ -41,6 +43,7 @@
public class PropertyManager {

private final CucableLogger logger;
private final FileIO fileIO;

private String sourceRunnerTemplateFile;
private String generatedRunnerDirectory;
Expand All @@ -55,8 +58,9 @@ public class PropertyManager {
private List<String> scenarioNames = new ArrayList<>();

@Inject
public PropertyManager(CucableLogger logger) {
public PropertyManager(final CucableLogger logger, final FileIO fileIO) {
this.logger = logger;
this.fileIO = fileIO;
}

public String getSourceRunnerTemplateFile() {
Expand All @@ -79,10 +83,21 @@ public List<CucableFeature> getSourceFeatures() {
return sourceFeatures;
}

public void setSourceFeatures(final String sourceFeatures) {
public void setSourceFeatures(final String sourceFeatures) throws MissingFileException {
String featuresToProcess;
if (sourceFeatures.startsWith("@")) {
featuresToProcess = fileIO.readContentFromFile(sourceFeatures.substring(1))
.replace("\n", ",");
} else {
featuresToProcess = sourceFeatures;
}
this.sourceFeatures = sourceFeaturePathsToCucableFeatureList(featuresToProcess.split(","));
}

private List<CucableFeature> sourceFeaturePathsToCucableFeatureList(final String[] sourceFeatures) {
List<CucableFeature> cucableFeatures = new ArrayList<>();
Pattern lineNumberPattern = Pattern.compile(":(\\d*)");
for (String sourceFeature : sourceFeatures.split(",")) {
for (String sourceFeature : sourceFeatures) {
String trimmedFeature = sourceFeature.trim();
StringBuffer resultBuffer = new StringBuffer();
Matcher matcher = lineNumberPattern.matcher(trimmedFeature);
Expand All @@ -98,8 +113,7 @@ public void setSourceFeatures(final String sourceFeatures) {
matcher.appendTail(resultBuffer);
cucableFeatures.add(new CucableFeature(resultBuffer.toString(), scenarioLineNumbers));
}

this.sourceFeatures = cucableFeatures;
return cucableFeatures;
}

public String getGeneratedFeatureDirectory() {
Expand Down Expand Up @@ -246,8 +260,8 @@ public void logProperties() {
String logLine = " - " + sourceFeature.getName();
if (sourceFeature.hasValidScenarioLineNumbers()) {
List<Integer> lineNumbers = sourceFeature.getLineNumbers();
logLine += String.format(" with %s %s",
Language.singularPlural(lineNumbers.size(), "line number", "line numbers"),
logLine += String.format(" (%s %s)",
Language.singularPlural(lineNumbers.size(), "line", "lines"),
lineNumbers.stream().map(String::valueOf).collect(Collectors.joining(",")));
}
logger.info(logLine, logLevels);
Expand Down
4 changes: 2 additions & 2 deletions plugin-code/src/main/java/com/trivago/vo/CucableFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import java.util.List;

public class CucableFeature {
private String name;
private List<Integer> lineNumbers;
private final String name;
private final List<Integer> lineNumbers;

public CucableFeature(final String name, final List<Integer> lineNumbers) {
this.name = name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

public class CucablePluginExceptionTest {

Expand Down
Loading

0 comments on commit 0035ee1

Please sign in to comment.