Junit 在生成Cucumber报告后,如何执行一些代码?
我使用Cucumber for jUnit runner运行BDD测试,如下所示:Junit 在生成Cucumber报告后,如何执行一些代码?,junit,cucumber-jvm,Junit,Cucumber Jvm,我使用Cucumber for jUnit runner运行BDD测试,如下所示: @RunWith(Cucumber.class) @CucumberOptions( format = {"pretty", "json:target/cucumber.json"}, glue = {"com.company.bdd.steps"}, features = {"classpath:bdd-scenarios"}, tags = {"~@skip"} ) publi
@RunWith(Cucumber.class)
@CucumberOptions(
format = {"pretty", "json:target/cucumber.json"},
glue = {"com.company.bdd.steps"},
features = {"classpath:bdd-scenarios"},
tags = {"~@skip"}
)
public class CucumberTests {
}
我想有美丽的HTML报告从
我制作了jUnit@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();
}
@AfterClass
公共静态void buildReport()引发异常{
List srcreeportjson=Collections.singletonList(“target/cucumber.json”);
配置=新配置(新文件(“目标”),“AEOS BDD集成测试”);
新的ReportBuilder(srcReportJson,配置);
}
问题是当执行@AfterClass
方法时,cucumber.json
是空的。因此,我无法构建漂亮的HTML报告
在构建json报告之后,是否有任何钩子可以用来执行一些代码
PS:CucumberV.1.1.8被使用,Java 1.7因此我无法尝试ExtendedCucumberRunner您考虑过添加关机钩子吗?关于如何添加一个的示例。
run()
方法中的代码应该在JVM关闭之前执行。您可以查看cucumber的自定义格式化程序:
将此建议发布在
“您不需要在cucumber中执行此操作。在用于运行cucumber测试的JUnit测试中使用@beforeclass和@afterclass注释。这样做的好处是只对路径或标记选项指定的功能运行
@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");
}
}
“谢谢您的建议,但我刚刚决定使用现有的,并在测试目标之后立即执行它的目标。我尝试了jUnit的
@AfterClass
,但调用太早,Cucumber JSON此时是空的:您尝试过等待它不为空吗?看这个。是的,它在@AfterClass
中工作。我在控制台中看到,当reporter内部的log4j试图注册另一个shutdownhook时,它也抛出'java.lang.IllegalStateException:Shutdown in progress',但生成了报告:)