Skip to content

Commit fbf2b54

Browse files
committed
Add readme to cucumber-junit
1 parent 3ea236b commit fbf2b54

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

junit/README.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
Cucumber JUnit
2+
==============
3+
4+
Use JUnit to execute cucumber scenarios.
5+
6+
Add the `cucumber-junit` dependency to your pom.
7+
8+
```xml
9+
<dependencies>
10+
[...]
11+
<dependency>
12+
<groupId>io.cucumber</groupId>
13+
<artifactId>cucumber-junit</artifactId>
14+
<version>${cucumber.version}</version>
15+
<scope>test</scope>
16+
</dependency>
17+
[...]
18+
</dependencies>
19+
```
20+
21+
Create an empty class that uses the Cucumber JUnit runner.
22+
23+
```java
24+
package com.example;
25+
26+
import cucumber.api.CucumberOptions;
27+
import cucumber.api.junit.Cucumber;
28+
import org.junit.runner.RunWith;
29+
30+
@RunWith(Cucumber.class)
31+
@CucumberOptions(plugin = "json:target/cucumber-report.json")
32+
public class RunCukesTest {
33+
}
34+
```
35+
36+
This will execute all scenarios in same package as the runner, by default glue code is also assumed to be in the same
37+
package. The `@CucumberOptions` can be used to provide
38+
[additional configuration](https://cucumber.io/docs/reference/jvm#list-configuration-options) to the runner.
39+
40+
41+
## Using JUnit Rules ##
42+
43+
Cucumber supports JUnits `@ClassRule`, `@BeforeClass` and `@AfterClass` annotations. These will executed before and
44+
after all features. Using these is not recommended as it limits the portability between different runners; they may not
45+
execute correctly when using the commandline, [IntelliJ IDEA](https://www.jetbrains.com/help/idea/cucumber.html) or
46+
[Cucumber-Eclipse](https://github.com/cucumber/cucumber-eclipse). Instead it is recommended to use Cucumbers `Before`
47+
and `After` hooks.
48+
49+
## Using other JUnit features ##
50+
51+
The Cucumber runner acts like a suite of a JUnit tests. As such other JUnit features such as Categories, Custom JUnit
52+
Listeners and Reporters can all be expected to work.
53+
54+
For more information on JUnit, see the [JUnit web site](http://www.junit.org).

junit/src/main/java/cucumber/api/junit/Cucumber.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@
3333
* Classes annotated with {@code @RunWith(Cucumber.class)} will run a Cucumber Feature.
3434
* In general, the runner class should be empty without any fields or methods.
3535
* For example:
36-
*
36+
* <p>
3737
* <blockquote><pre>
3838
* &#64;RunWith(Cucumber.class)
3939
* &#64;CucumberOptions(plugin = "pretty")
4040
* public class RunCukesTest {
41-
*
41+
* <p>
4242
* }
4343
* </pre></blockquote>
4444
* <p>
@@ -48,7 +48,9 @@
4848
* Additional hints can be given to Cucumber by annotating the class with {@link CucumberOptions}.
4949
* <p>
5050
* Cucumber also supports JUnits {@link ClassRule}, {@link BeforeClass} and {@link AfterClass} annotations.
51-
* These will be invoked around the suite of features" and moved to the end of the java doc.
51+
* These will be invoked around the suite of features. Using these is not recommended as it limits the portability
52+
* between different runners; they may not execute correctly when using the commandline, IntelliJ IDEA or
53+
* Cucumber-Eclipse. Instead it is recommended to use Cucumbers `Before` and `After` hooks.
5254
*
5355
* @see CucumberOptions
5456
*/

0 commit comments

Comments
 (0)