提问人:darklord84 提问时间:5/10/2022 更新时间:5/10/2022 访问量:989
空手道 1.0.1 的 Allure Report 仅使用一个测试用例生成报告
Allure Report with karate 1.0.1 generating report with just one test case
问:
我正在从事一个 maven 项目,我正在通过 jenkins 使用 karate 1.0.1 创建黄瓜报告和诱惑报告。但是,即使生成了详细的黄瓜报告,我在诱惑报告中也只得到了一个测试用例
我的 TestParallelRunner.java 文件:
@CucumberOptions(plugin = {"pretty" , "html:target/cucumber-html-reports", "io.qameta.allure.cucumber4jvm.AllureCucumber5Jvm","json:target/cucumber/cucumber.json"})
//@KarateOptions(tags = "~@ignore")
public class TestParallelRunner {
@Test
public void testParallel() {
//String outputDir = "target//surefire-reports";
Builder testRun = new Builder();
testRun.path("classpath:com/api/automation/Features").outputCucumberJson(true).tags("~@ignore");
Results results = testRun.parallel(3);
generateReport(results.getReportDir());
Assertions.assertEquals(0, results.getFailCount(), "There are some Failed Scenarios");
}
public static void generateReport(String reportDirLocation) {
File reportDir=new File(reportDirLocation);
Collection<File> jsonFiles = FileUtils.listFiles(reportDir, new String[] {"json"}, true);
//jsonFiles.add(File("cucumber-report.json"));
List<String> jsonPaths = new ArrayList<>();
//jsonFiles.add("cucumber-report-2.json");
jsonFiles.forEach(file -> jsonPaths.add(file.getAbsolutePath()));
Configuration config = new Configuration(new File("target"), "Cucumber Report");
ReportBuilder reportBuilder = new ReportBuilder(jsonPaths, config);
reportBuilder.generateReports();
}
}
我的 pom.xml 文件:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>11</java.version>
<maven.compiler.version>3.8.1</maven.compiler.version>
<maven.surefire.version>2.22.2</maven.surefire.version>
<karate.version>1.0.1</karate.version>
<allure.maven.version>2.11.2</allure.maven.version>
<allure-junit5.version>2.17.3</allure-junit5.version>
</properties>
<dependencies>
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-junit5</artifactId>
<version>${karate.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/net.masterthought/cucumber-reporting -->
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>5.6.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.qameta.allure/allure-maven -->
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-maven</artifactId>
<version>${allure.maven.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.qameta.allure/allure-cucumber5-jvm -->
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-cucumber5-jvm</artifactId>
<version>2.17.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.qameta.allure/allure-junit5 -->
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-junit5</artifactId>
<version>${allure-junit5.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<testResources>
<testResource>
<directory>src/test/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<configuration>
<encoding>UTF-8</encoding>
<source>${java.version}</source>
<target>${java.version}</target>
<compilerArgument>-Werror</compilerArgument>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.version}</version>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
<testFailureIgnore>true</testFailureIgnore>
<systemProperties>
<property>
<name>allure.results.directory</name>
<value> ${project.build.directory}/allure-results</value>
</property>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
</project>
我的 jenkins 管道中的 My Allure 报告:
allure([
includeProperties: false,
jdk: '',
properties:[],
reportBuildPolicy:'ALWAYS',
results: [[path: '/allure-results']]
]
)
但是我的 allure-results 文件夹中创建的 json 文件仅包含以下条目:
{"uuid":"XXXXXXX-XXXXX-XXXXXX","historyId":"XXXXXXXXXXXXXXXXXX","testCaseId":"[engine:junit-jupiter]/[class:com.api.automation.TestParallelRunner]/[method:testParallel()]","testCaseName":"testParallel()","fullName":"com.api.automation.TestParallelRunner.testParallel","labels":[{"name":"junit.platform.uniqueid","value":"[engine:junit-jupiter]/[class:com.api.automation.TestParallelRunner]/[method:testParallel()]"},{"name":"host","value":"XXXXXX"},{"name":"thread","value":"XXXXXXX.main(1)"},{"name":"framework","value":"junit-platform"},{"name":"language","value":"java"},{"name":"package","value":"com.api.automation.TestParallelRunner"},{"name":"testClass","value":"com.api.automation.TestParallelRunner"},{"name":"testMethod","value":"testParallel"},{"name":"suite","value":"com.api.automation.TestParallelRunner"}],"links":[],"name":"testParallel()","status":"passed","stage":"finished","description":"","steps":[],"attachments":[],"parameters":[],"start":1652145767274,"stop":1652145775326}
因此,无法像 cucumber 报告显示的那样获得完整的测试执行图片:
答:
1赞
Peter Thomas
5/10/2022
#1
几点:
@CucumberOptions
在空手道中不受支持,请阅读文档:https://github.com/karatelabs/karate#parallel-execution- 确保告诉 Karate 发出 Cucumber JSON: https://github.com/karatelabs/karate/wiki/1.0-upgrade-guide#java-projects
- 为了更好地衡量,请使用最新版本(1.2.0)
- 另请参阅: https://stackoverflow.com/a/54527955/143475
评论
0赞
darklord84
5/10/2022
感谢您的快速回复彼得。我将尝试检查升级到 1.2.0 是否有帮助。此外,我正在我的 Runner 文件中发出 Cucumber JSON。 如果这是不正确的,请告诉我?testRun.path("classpath:com/api/automation/Features").outputCucumberJson(true).tags("~@ignore");
0赞
Peter Thomas
5/10/2022
@darklord84看起来是正确的,但如果您仍需要支持,请按照以程操作: github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue
0赞
Parashuram
12/19/2023
@darklord84 你终于能够跑到诱惑报告了吗?我们目前也处于类似的情况。如果它工作正常,那么如果您分享一些代码片段会有所帮助。谢谢!
评论