Simple utility classes to gather information about your JBehave project and execution.
Easily get all steps and duplicate steps in your project by using JBehaveStepScanner
We can process the result as per the requirement.
@org.junit.Before
public void verifySteps() {
JBehaveStepScanner jBehaveStepScanner = new JBehaveStepScanner(
"com.everwhimsical.jbehave.step.classes.clean",
"com.everwhimsical.jbehave.step.classes.duplicate");
List<JBehaveStepInfo> allSteps = jBehaveStepScanner.getAllSteps();
allSteps.forEach(System.out::println);
}
By default, Given
, When
, Then
annotations are scanned. To include scanning of @Alias
and @Aliases
annotations, set the following attribute.
jBehaveStepScanner.setAliasScan(true);
Using the duplicate result list, it can be used to fail the execution before executing stories.
@org.junit.Before
public void verifySteps() {
JBehaveStepScanner jBehaveStepScanner = new JBehaveStepScanner(
"com.everwhimsical.jbehave.step.classes.clean",
"com.everwhimsical.jbehave.step.classes.duplicate");
List<DuplicateJBehaveStepInfo> duplicateSteps = jBehaveStepScanner.getDuplicateSteps();
duplicateSteps.forEach(System.out::println);
if (duplicateSteps.size() > 0) {
Assert.fail("Duplicate steps found");
}
}
- A step is considered duplicate if the annotation and step name is present more than once.
- If alias scanning is included, steps are considered duplicate if step name is present more than once.
Get information about the current Story, Scenario, Step, Examples in a thread-safe manner using JBehaveExecution
Add the ExecutionModelReporter to your configuration as below and use the methods in JBehaveExecution.
@Override
public Configuration configuration() {
return new MostUsefulConfiguration()
.useStoryPathResolver(embeddableClass -> "com/everwhimsical/jbehave/Simple.story")
.useStoryReporterBuilder(
new StoryReporterBuilder()
.withDefaultFormats()
.withReporters(new ExecutionModelReporter())
.withFormats(Format.CONSOLE));
}
To get information about entities, use the below methods
- Execution -> JBehaveExecution.getExecution
- Story -> JBehaveExecution.getStory
- Scenario -> JBehaveExecution.getScenario
- Step -> JBehaveExecution.getStep
Using these entities build your custom reporter with ease.