Cucumber JUnit (Deprecated)
===========================
> [!IMPORTANT]
> **JUnit 4 is in maintenance mode.**
> For JUnit 5+ use the [Cucumber JUnit Platform Engine](../cucumber-junit-platform-engine)
Use JUnit 4 to execute Cucumber scenarios. To use add the `cucumber-junit`
dependency to your `pom.xml` and use the [`cucumber-bom`](../cucumber-bom/README.md)
for dependency management:
```xml
[...]
io.cucumber
cucumber-junit
test
[...]
```
Create an empty class that uses the Cucumber JUnit runner.
```java
package com.example;
import io.cucumber.junit.CucumberOptions;
import io.cucumber.junit.Cucumber;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@CucumberOptions(plugin = "message:target/cucumber-report.ndjson")
public class RunCucumberTest {
}
```
This will execute all scenarios in the same package as the runner; by default, glue
code is also assumed to be in the same package. The `@CucumberOptions` can be used to provide
[additional configuration](https://docs.cucumber.io/cucumber/api/#list-configuration-options)
to the runner.
## Using JUnit Rules ##
Cucumber supports JUnit's `@ClassRule`, `@BeforeClass`, and `@AfterClass`
annotations. These will be executed before and
after all scenarios. Using these is not recommended as it limits portability
between different runners; they may not
execute correctly when using the command line, [IntelliJ IDEA](https://www.jetbrains.com/help/idea/cucumber.html), or
[Cucumber-Eclipse](https://github.com/cucumber/cucumber-eclipse). Instead, it is
recommended to [use Cucumber's hooks](../cucumber-java#beforeall--afterall).
## Using other JUnit features ##
The Cucumber runner acts like a suite of JUnit tests. As such, other JUnit
features like custom JUnit
Listeners and Reporters can all be expected to work.
For more information on JUnit, see the [JUnit website](http://www.junit.org).
## Assume ##
Through [Assume](https://junit.org/junit4/javadoc/4.12/org/junit/Assume.html)
and [Assumptions](https://docs.junit.org/current/writing-tests/assumptions.html)
JUnit4 and JUnit5 provide:
> a collection of utility methods that support conditional test execution based
> on assumptions.
>
> In direct contrast to failed assertions, failed assumptions do not result in a
> test failure; rather, a failed assumption results in a test being aborted.
>
> Assumptions are typically used whenever it does not make sense to continue
> execution of a given test method — for example, if the test depends on
> something that does not exist in the current runtime environment.
The Cucumber runner supports `Assume` and will mark skipped scenarios as
skipped.
## Parallel Execution with Maven ##
Cucumber JUnit supports parallel execution of feature files across multiple
threads. To enable this with Maven, set the `parallel` property to either
`methods` or `both`.
```xml
maven-surefire-plugin
${maven-surefire-plugin.version}
both
4
```