How do I execute some code after generating a Cucumber report?

I am using Cucumber for jUnit runner to run BDD tests like this:

@RunWith(Cucumber.class)
@CucumberOptions(
    format = {"pretty", "json:target/cucumber.json"},
    glue = {"com.company.bdd.steps"},
    features = {"classpath:bdd-scenarios"},
    tags = {"~@skip"}
)
public class CucumberTests {
}

      

I would like to have nice HTML reports from https://github.com/damianszczepanik/cucumber-reporting

And I made a jUnit method @AfterClass

:

@AfterClass
public static void buildReport() throws Exception {
    List<String> srcReportJson = Collections.singletonList("target/cucumber.json");
    Configuration configuration = new Configuration(new File("target"), "AEOS BDD Integration Tests");
    new ReportBuilder(srcReportJson, configuration).generateReports();
}

      

The problem is that it is cucumber.json

empty when executing the method @AfterClass

. Hence, I am unable to generate a pretty HTML report.

Is there some hook I can use to execute some code after the json cucumber report is already built?

PS: Cucumber v.1.1.8 is used by Java 1.7 too, so I couldn't try ExtendedCucumberRunner

+3


source to share


4 answers


Thanks for your suggestions, but I decided to use the already existing Maven plugin and execute its target right after the test target.



+1


source


You can take a look at a custom cucumber formatter: gherkin.formatter class



+2


source


+1


source


wjpowell posted this proposal in cucumber-jvm issues :

"You don't need to do this in cucumber. Use the @beforeclass and @afterclass annotation from the JUnit test used to run cucumber tests. This has the advantage of only working for functions specified in paths or tags.

@RunWith(Cucumber.class)
@Cucumber.Options(format = {"html:target/cucumber-html-report", "json-pretty:target/cucumber-json-report.json"})
public class RunCukesTest {

    @BeforeClass
    public static void setup() {
        System.out.println("Ran the before");
    }

    @AfterClass
    public static void teardown() {
        System.out.println("Ran the after");
    }
}

      

"

0


source







All Articles