Skip to content

Simple utility classes to gather information about your JBehave project and execution.

License

Notifications You must be signed in to change notification settings

EverWhimsical/jbehave-extras

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JBehave Extras

Build Status License Maven Central Known Vulnerabilities

Simple utility classes to gather information about your JBehave project and execution.

Usage

JBehaveStepScanner

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);

Duplicate Steps

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");
        }
    }

Duplicate Condition

  • 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.

JBehaveExecution

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

Using these entities build your custom reporter with ease.