-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Java] Add BeforeAll and AfterAll hooks (#1876)
`BeforeAll` and `AfterAll` hooks are executed before all scenarios are executed and after all scenarios have been executed. A hook is declared by annotating a method. This methods must be static and do not take any arguments. Hooks are global, all hooks declared in any step definition class will be executed. The order in which hooks are executed is not defined. An explicit order can be provided by using the `order` property in the annotation. ```java package io.cucumber.example; import io.cucumber.java.AfterAll; import io.cucumber.java.BeforeAll; public class StepDefinitions { @BeforeAll public static void beforeAll() { // Runs before all scenarios } @afterall public static void afterAll() { // Runs after all scenarios } } ``` Notes: 1. When used in combination with Junit 5, Maven Surefire, and/or Failsafe use version `3.0.0-M5` or later. 2. When used in combination with Junit 5 and InteliJ IDEA failures in before all and after all hooks do not fail a test run. Fixes: #515
- Loading branch information
1 parent
71bb1cc
commit 3bc80b9
Showing
53 changed files
with
1,146 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
core/src/main/java/io/cucumber/core/backend/StaticHookDefinition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.cucumber.core.backend; | ||
|
||
import org.apiguardian.api.API; | ||
|
||
@API(status = API.Status.EXPERIMENTAL) | ||
public interface StaticHookDefinition extends Located { | ||
|
||
void execute(); | ||
|
||
int getOrder(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 2 additions & 16 deletions
18
core/src/main/java/io/cucumber/core/exception/CompositeCucumberException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,12 @@ | ||
package io.cucumber.core.exception; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public final class CompositeCucumberException extends CucumberException { | ||
|
||
private final List<Throwable> causes; | ||
|
||
public CompositeCucumberException(List<Throwable> causes) { | ||
super(String.format("There were %d exceptions:", causes.size())); | ||
this.causes = causes; | ||
} | ||
|
||
public List<Throwable> getCauses() { | ||
return Collections.unmodifiableList(this.causes); | ||
} | ||
|
||
public String getMessage() { | ||
return super.getMessage() + this.causes.stream() | ||
.map(e -> String.format(" %s(%s)", e.getClass().getName(), e.getMessage())) | ||
.collect(Collectors.joining("\n", "\n", "")); | ||
super(String.format("There were %d exceptions. The details are in the stacktrace below.", causes.size())); | ||
causes.forEach(this::addSuppressed); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.