我正在使用 Cucumber报告 api来获得更好的报告。我的项目不是 Maven 项目,现在无法更改项目结构。所以我添加了对我的项目的所有依赖项,但现在仍然出现“java.lang.IllegalArgumentException:文件'target/cucumber.json'不包含功能!”之类的错误。
所有添加的 jar 和版本如下所示。
我还在这里添加了我的 runner 类,这可能有助于调试。
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.junit.AfterClass;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.SnippetType;
import cucumber.api.junit.Cucumber;
import net.masterthought.cucumber.Configuration;
import net.masterthought.cucumber.ReportBuilder;
@RunWith(Cucumber.class)
@CucumberOptions(
plugin = {
"html:target/cucumber-html-report",
"json:target/cucumber.json"
},features ={"./sample.feature"},
glue ={"com/automation/steps"},strict = true,
dryRun= false,monochrome = true, snippets= SnippetType.CAMELCASE)
/*public class Runner extends AbstractTestNGCucumberTests{
}*/
public class Runner {
@AfterClass
public static void generateReport(){
File reportOutputDirectory = new File("target");
List<String> jsonFiles = new ArrayList<>();
jsonFiles.add("target/cucumber.json");
String jenkinsBasePath = "";
String buildNumber = "1";
String projectName = "cucumber-jvm";
boolean skippedFails = true;
boolean pendingFails = false;
boolean undefinedFails = true;
boolean missingFails = true;
boolean runWithJenkins = false;
boolean parallelTesting = false;
Configuration configuration = new Configuration(reportOutputDirectory, projectName);
// optionally only if you need
configuration.setStatusFlags(skippedFails, pendingFails, undefinedFails, missingFails);
configuration.setParallelTesting(parallelTesting);
configuration.setJenkinsBasePath(jenkinsBasePath);
configuration.setRunWithJenkins(runWithJenkins);
configuration.setBuildNumber(buildNumber);
ReportBuilder reportBuilder = new ReportBuilder(jsonFiles, configuration);
reportBuilder.generateReports();
}
}
我观察到 feature-overview.html 是在文件夹结构下生成的,但是当我打开此文件时它已损坏,它在此文件上显示此错误。