如何使用空手道、Cucumber 和 Java 生成多个空手道报告?以下代码仅从第二次 test2 运行生成测试。正确的方法是什么?
class ApiMockRunner {
private static List<String> jsonPaths = new ArrayList<>();
@Test
public void testSample() {
Results test1Results = Runner.path("classpath:Karate/test1.feature")
.outputCucumberJson(true)
.karateEnv(System.getProperty("karate.env"))
.parallel(5);
addJsonFiles(test1Results.getReportDir());
Results test2results = Runner.path("classpath:Karate/test2results.feature")
.outputCucumberJson(true)
.karateEnv(System.getProperty("karate.env"))
.parallel(5);
addJsonFiles(test2results.getReportDir());
}
public void addJsonFiles(String karateOutputPath) {
Collection<File> jsonFiles = FileUtils.listFiles(new File(karateOutputPath), new String[] {"json"}, true);
for (File jsonFileItem : jsonFiles) {
jsonPaths.add(jsonFileItem.getAbsolutePath());
}
}
@AfterAll
public static void createConfig() {
String testProjectName = "finalData";
Configuration config = new Configuration(new File("target/"+testProjectName), testProjectName);
ReportBuilder reportBuilder = new ReportBuilder(jsonPaths, config);
reportBuilder.generateReports();
}
}
通常您会一次性运行所有测试。默认情况下,空手道会将“最新测试结果”复制到文件夹中,然后运行新测试,因此您的所有报告都在那里。
这个答案可能会给您一些如何继续的提示:https://stackoverflow.com/a/69490494/143475