Skip to content

Commit 72acd6c

Browse files
authored
Merge pull request temyers#160 from sureshnath/counterCustomisablePattern
Counter character length customisable pattern
2 parents 4f549db + 3886d7c commit 72acd6c

File tree

11 files changed

+366
-14
lines changed

11 files changed

+366
-14
lines changed

readme.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Please refer to the integration tests for example usage:
9999
</tags>
100100
<!-- Generate TestNG runners instead of JUnit ones. -->
101101
<useTestNG>false</useTestNG>
102-
<!-- The naming scheme to use for the generated test classes. One of 'simple' or 'feature-title' -->
102+
<!-- The naming scheme to use for the generated test classes. One of ['simple', 'feature-title', 'pattern'] -->
103103
<namingScheme>simple</namingScheme>
104104
<!-- The class naming pattern to use. Only required/used if naming scheme is 'pattern'.-->
105105
<namingPattern>Parallel{c}IT</namingPattern>
@@ -189,18 +189,25 @@ The naming scheme used for the generated files is controlled by the `namingSchem
189189

190190
| Property | Generated Name |
191191
| ------------- | -------------- |
192-
| simple | `ParallelXXIT.java`, where `XX` is a one up counter.
193-
| feature-title | The name is generated based on the feature title with the following rules to ensure it is a valid classname:
194-
* Spaces are removed, camel-casing the title.
192+
| simple | `ParallelXXIT.java`, where `XX` is a one up counter.|
193+
| feature-title | The name is generated based on the feature title with a set of rules to ensure it is a valid classname. The reules are detailed in the next subsection below. |
194+
| pattern | Generate the filename based on the `namingPattern` property.|
195+
196+
By default, generated test files use the `simple` naming strategy.
197+
198+
#### Feature-title Naming Scheme - rules ####
199+
200+
* Spaces are removed, camel-casing the title
195201
* If the feature file starts with a digit, the classname is prefixed with '_'
196-
* A on up counter is appended to the classname, to prevent clashes. |
197-
| pattern | Generate the filename based on the `namingPattern` property.
202+
* A one up counter is appended to the classname, to prevent clashes.
203+
204+
#### Pattern Naming Scheme - tokens ####
205+
198206
The following tokens can be used in the pattern:
199207
* `{f}` Converts the feature file name to a valid class name using the rules for feature-title, apart from the one up counter.
200-
* `{c}` Adds a one up counter. |
201-
* `{c:n}` Adds a one up counter modulo n (useful for selecting tests for parallelisation). |
202-
203-
By default, generated test files use the `simple` naming strategy.
208+
* `{c}` Adds a one up counter.
209+
* `{c:n}` Adds a one up counter modulo n (useful for selecting tests for parallelisation).
210+
* By default counter value is zero padded to two characters and modulo counter is not padded at all. If you need a different zero padded length, this can be achieved by prefixing the character `c` by the length required - for example `{3c}` will yield `001` instead of `01`
204211

205212
#### Note on Pattern Naming Scheme ####
206213
The `pattern` naming scheme is for advanced usage only.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.github.temyers.it</groupId>
8+
<artifactId>simple-it</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<description>A case of complex name involving counter character length</description>
12+
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
<cucumber.version>1.2.2</cucumber.version>
16+
</properties>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>info.cukes</groupId>
21+
<artifactId>cucumber-junit</artifactId>
22+
<version>${cucumber.version}</version>
23+
</dependency>
24+
<dependency>
25+
<groupId>info.cukes</groupId>
26+
<artifactId>cucumber-java</artifactId>
27+
<version>${cucumber.version}</version>
28+
</dependency>
29+
</dependencies>
30+
31+
<build>
32+
<plugins>
33+
<plugin>
34+
<groupId>@project.groupId@</groupId>
35+
<artifactId>@project.artifactId@</artifactId>
36+
<version>@project.version@</version>
37+
<executions>
38+
<execution>
39+
<id>generateRunners</id>
40+
<phase>generate-test-sources</phase>
41+
<goals>
42+
<goal>generateRunners</goal>
43+
</goals>
44+
<configuration>
45+
<glue>
46+
<package>foo</package>
47+
<package>bar</package>
48+
</glue>
49+
<namingScheme>pattern</namingScheme>
50+
<namingPattern>Foo{f}Counter{1c}Mod{2c:3}Again{4c}Mod{5c:6}</namingPattern>
51+
</configuration>
52+
</execution>
53+
</executions>
54+
</plugin>
55+
</plugins>
56+
</build>
57+
</project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Feature: Feature1
2+
3+
Scenario: Generate Junit Runner for each feature file
4+
Given I have feature files
5+
When I generate Maven sources
6+
Then the file "target/generated-test-sources/1IT.java" should exist
7+
And it should contain:
8+
"""
9+
@RunWith(Cucumber.class)
10+
@CucumberOptions(
11+
strict = true,
12+
features = {"classpath:features/feature1.feature"},
13+
format = {"json:target/cucumber-parallel/1.json",
14+
"pretty"},
15+
monochrome = false,
16+
tags = {"@complete", "@accepted"},
17+
glue = {"foo", "bar"})
18+
public class Parallel01IT {
19+
}
20+
"""
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Feature: Feature1
2+
3+
Scenario: Generate Junit Runner for each feature file
4+
Given I have feature files
5+
When I generate Maven sources
6+
Then the file "target/generated-test-sources/1IT.java" should exist
7+
And it should contain:
8+
"""
9+
@RunWith(Cucumber.class)
10+
@CucumberOptions(
11+
strict = true,
12+
features = {"classpath:features/feature2.feature"},
13+
format = {"json:target/cucumber-parallel/2.json", "pretty"},
14+
monochrome = false,
15+
tags = {"@complete", "@accepted"},
16+
glue = {"foo", "bar"})
17+
public class Parallel02IT {
18+
}
19+
"""
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Feature: Feature1
2+
3+
Scenario: Generate Junit Runner for each feature file
4+
Given I have feature files
5+
When I generate Maven sources
6+
Then the file "target/generated-test-sources/1IT.java" should exist
7+
And it should contain:
8+
"""
9+
@RunWith(Cucumber.class)
10+
@CucumberOptions(
11+
strict = true,
12+
features = {"classpath:features/feature2.feature"},
13+
format = {"json:target/cucumber-parallel/2.json", "pretty"},
14+
monochrome = false,
15+
tags = {"@complete", "@accepted"},
16+
glue = {"foo", "bar"})
17+
public class Parallel02IT {
18+
}
19+
"""
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Feature: Feature1
2+
3+
Scenario: Generate Junit Runner for each feature file
4+
Given I have feature files
5+
When I generate Maven sources
6+
Then the file "target/generated-test-sources/1IT.java" should exist
7+
And it should contain:
8+
"""
9+
@RunWith(Cucumber.class)
10+
@CucumberOptions(
11+
strict = true,
12+
features = {"classpath:features/feature2.feature"},
13+
format = {"json:target/cucumber-parallel/2.json", "pretty"},
14+
monochrome = false,
15+
tags = {"@complete", "@accepted"},
16+
glue = {"foo", "bar"})
17+
public class Parallel02IT {
18+
}
19+
"""
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Feature: Feature1
2+
3+
Scenario: Generate Junit Runner for each feature file
4+
Given I have feature files
5+
When I generate Maven sources
6+
Then the file "target/generated-test-sources/1IT.java" should exist
7+
And it should contain:
8+
"""
9+
@RunWith(Cucumber.class)
10+
@CucumberOptions(
11+
strict = true,
12+
features = {"classpath:features/feature1.feature"},
13+
format = {"json:target/cucumber-parallel/1.json",
14+
"pretty"},
15+
monochrome = false,
16+
tags = {"@complete", "@accepted"},
17+
glue = {"foo", "bar"})
18+
public class Parallel01IT {
19+
}
20+
"""
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Feature: Feature1
2+
3+
Scenario: Generate Junit Runner for each feature file
4+
Given I have feature files
5+
When I generate Maven sources
6+
Then the file "target/generated-test-sources/1IT.java" should exist
7+
And it should contain:
8+
"""
9+
@RunWith(Cucumber.class)
10+
@CucumberOptions(
11+
strict = true,
12+
features = {"classpath:features/feature1.feature"},
13+
format = {"json:target/cucumber-parallel/1.json",
14+
"pretty"},
15+
monochrome = false,
16+
tags = {"@complete", "@accepted"},
17+
glue = {"foo", "bar"})
18+
public class Parallel01IT {
19+
}
20+
"""
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
import org.junit.Assert
2+
3+
import static org.hamcrest.Matchers.equalToIgnoringWhiteSpace
4+
5+
File buildDirectory = new File(basedir, "target")
6+
7+
File suite01 = new File(basedir, "target/generated-test-sources/cucumber/FooFeature1Counter1Mod00Again0001Mod00000.java")
8+
File suite02 = new File(basedir, "target/generated-test-sources/cucumber/FooFeature2Counter2Mod01Again0002Mod00001.java")
9+
File suite03 = new File(basedir, "target/generated-test-sources/cucumber/FooFeature3Counter3Mod02Again0003Mod00002.java")
10+
File suite04 = new File(basedir, "target/generated-test-sources/cucumber/FooFeature4Counter4Mod00Again0004Mod00003.java")
11+
File suite05 = new File(basedir, "target/generated-test-sources/cucumber/FooFeature5Counter5Mod01Again0005Mod00004.java")
12+
File suite06 = new File(basedir, "target/generated-test-sources/cucumber/FooFeature6Counter6Mod02Again0006Mod00005.java")
13+
14+
File feature1 = new File(basedir, "/src/test/resources/features/feature1.feature")
15+
File feature2 = new File(basedir, "/src/test/resources/features/feature2.feature")
16+
File feature3 = new File(basedir, "/src/test/resources/features/feature3.feature")
17+
File feature4 = new File(basedir, "/src/test/resources/features/feature4.feature")
18+
File feature5 = new File(basedir, "/src/test/resources/features/feature5.feature")
19+
File feature6 = new File(basedir, "/src/test/resources/features/feature6.feature")
20+
21+
assert suite01.isFile()
22+
assert suite02.isFile()
23+
assert suite03.isFile()
24+
assert suite04.isFile()
25+
assert suite05.isFile()
26+
assert suite06.isFile()
27+
28+
String expected01 =
29+
"""import org.junit.runner.RunWith;
30+
31+
import cucumber.api.CucumberOptions;
32+
import cucumber.api.junit.Cucumber;
33+
34+
@RunWith(Cucumber.class)
35+
@CucumberOptions(
36+
strict = true,
37+
features = {"${feature1.absolutePath}"},
38+
plugin = {"json:${buildDirectory.absolutePath}/cucumber-parallel/1.json"},
39+
monochrome = false,
40+
tags = {},
41+
glue = {"foo", "bar"})
42+
public class FooFeature1Counter1Mod00Again0001Mod00000 {
43+
}"""
44+
45+
String expected02 =
46+
"""import org.junit.runner.RunWith;
47+
48+
import cucumber.api.CucumberOptions;
49+
import cucumber.api.junit.Cucumber;
50+
51+
@RunWith(Cucumber.class)
52+
@CucumberOptions(
53+
strict = true,
54+
features = {"${feature2.absolutePath}"},
55+
plugin = {"json:${buildDirectory.absolutePath}/cucumber-parallel/2.json"},
56+
monochrome = false,
57+
tags = {},
58+
glue = {"foo", "bar"})
59+
public class FooFeature2Counter2Mod01Again0002Mod00001 {
60+
}"""
61+
62+
String expected03 =
63+
"""import org.junit.runner.RunWith;
64+
65+
import cucumber.api.CucumberOptions;
66+
import cucumber.api.junit.Cucumber;
67+
68+
@RunWith(Cucumber.class)
69+
@CucumberOptions(
70+
strict = true,
71+
features = {"${feature3.absolutePath}"},
72+
plugin = {"json:${buildDirectory.absolutePath}/cucumber-parallel/3.json"},
73+
monochrome = false,
74+
tags = {},
75+
glue = {"foo", "bar"})
76+
public class FooFeature3Counter3Mod02Again0003Mod00002 {
77+
}"""
78+
79+
String expected04 =
80+
"""import org.junit.runner.RunWith;
81+
82+
import cucumber.api.CucumberOptions;
83+
import cucumber.api.junit.Cucumber;
84+
85+
@RunWith(Cucumber.class)
86+
@CucumberOptions(
87+
strict = true,
88+
features = {"${feature4.absolutePath}"},
89+
plugin = {"json:${buildDirectory.absolutePath}/cucumber-parallel/4.json"},
90+
monochrome = false,
91+
tags = {},
92+
glue = {"foo", "bar"})
93+
public class FooFeature4Counter4Mod00Again0004Mod00003 {
94+
}"""
95+
96+
String expected05 =
97+
"""import org.junit.runner.RunWith;
98+
99+
import cucumber.api.CucumberOptions;
100+
import cucumber.api.junit.Cucumber;
101+
102+
@RunWith(Cucumber.class)
103+
@CucumberOptions(
104+
strict = true,
105+
features = {"${feature5.absolutePath}"},
106+
plugin = {"json:${buildDirectory.absolutePath}/cucumber-parallel/5.json"},
107+
monochrome = false,
108+
tags = {},
109+
glue = {"foo", "bar"})
110+
public class FooFeature5Counter5Mod01Again0005Mod00004 {
111+
}"""
112+
113+
String expected06 =
114+
"""import org.junit.runner.RunWith;
115+
116+
import cucumber.api.CucumberOptions;
117+
import cucumber.api.junit.Cucumber;
118+
119+
@RunWith(Cucumber.class)
120+
@CucumberOptions(
121+
strict = true,
122+
features = {"${feature6.absolutePath}"},
123+
plugin = {"json:${buildDirectory.absolutePath}/cucumber-parallel/6.json"},
124+
monochrome = false,
125+
tags = {},
126+
glue = {"foo", "bar"})
127+
public class FooFeature6Counter6Mod02Again0006Mod00005 {
128+
}"""
129+
130+
Assert.assertThat(suite01.text, equalToIgnoringWhiteSpace(expected01))
131+
Assert.assertThat(suite02.text, equalToIgnoringWhiteSpace(expected02))
132+
Assert.assertThat(suite03.text, equalToIgnoringWhiteSpace(expected03))
133+
Assert.assertThat(suite04.text, equalToIgnoringWhiteSpace(expected04))
134+
Assert.assertThat(suite05.text, equalToIgnoringWhiteSpace(expected05))
135+
Assert.assertThat(suite06.text, equalToIgnoringWhiteSpace(expected06))

0 commit comments

Comments
 (0)