Reputation: 8056
I use 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 beautiful HTML reports from https://github.com/damianszczepanik/cucumber-reporting
And i made jUnit @AfterClass
method:
@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 cucumber.json
is empty when @AfterClass
method executes. Hence i can't build pretty HTML report.
Is there any hook which i can use to execute some code after cucumber json report is already built?
PS: Cucumber v.1.1.8 is used and Java 1.7 so i was not able to try ExtendedCucumberRunner
Upvotes: 3
Views: 3574
Reputation: 8056
Thank you for your suggestions but I just decided to use already existing Maven plugin and execute it's goal right after test goal.
Upvotes: 1
Reputation: 2819
wjpowell posted this suggestion in the cucumber-jvm issues:
"You don't need to do this in cucumber. Use the @beforeclass and @afterclass annotation from within the JUnit test used to run the cucumber tests. This has the benefit of running only for the features specified by the paths or tags options.
@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");
}
}
"
Upvotes: 0