Allure Report with karate 1.0.1 只用一个测试用例生成报告
Allure Report with karate 1.0.1 generating report with just one test case
我正在从事一个 Maven 项目,我正在通过 jenkins 使用空手道 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>
我的 Allure 报告在我的 jenkins 管道中:
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 报告显示的方式获得完整的测试执行图片:
几点:
空手道不支持 @CucumberOptions
,请阅读文档:https://github.com/karatelabs/karate#parallel-execution
- 确保你告诉空手道发射黄瓜JSON:https://github.com/karatelabs/karate/wiki/1.0-upgrade-guide#java-projects
- 目前最好使用最新版本 (1.2.0)
- 另请参阅:
我正在从事一个 Maven 项目,我正在通过 jenkins 使用空手道 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>
我的 Allure 报告在我的 jenkins 管道中:
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 报告显示的方式获得完整的测试执行图片:
几点:
-
空手道不支持
@CucumberOptions
,请阅读文档:https://github.com/karatelabs/karate#parallel-execution- 确保你告诉空手道发射黄瓜JSON:https://github.com/karatelabs/karate/wiki/1.0-upgrade-guide#java-projects
- 目前最好使用最新版本 (1.2.0)
- 另请参阅: