https://www.cnblogs.com/wxy990118/p/10696737.html
写接口的程序
https://www.sohu.com/a/305131547_470023
maven 创建工程
Cucumber启动类配置
1 @CucumberOptions ( features = "src/test/resources",
2 glue = {"Steps"},
3 tags = {"@smokeTest"},
4 plugin = {"pretty", "html:target/cucumber-report", "json:target/cucumber-report/cucumber.json"} )
5 public class CucumberStart extends AbstractTestNGCucumberTests { }
- 测试执行文件
Cucumber的测试执行文件一般为一个空的Junit Test Case,即不需要Test注释,更不需要Before和After等注释。当必须添加RunWith注释和CucumberOptions注释。
RunWith注释每一个Cucumber框架的测试文件都是相同的,为RunWith(Cucumber.class)。CucumberOption注释的内容是根据实际情况需要手动更改的。
CucumberOptions注释选项一般有features、glue、monochrome和dryrun等。其中。features和glue是必写项,monochrome和dryrun选填项。
features定义了.feature文件的相对路径,格式为features=“.feature文件在该工程的文件夹/.feature文件的名字”。eg. features="Feature/calculatorAdd.feature"
glue定义了Step-difinition的包名,格式为glue=”完整的包名”。eg. test.java.cucumberDefinition。
monochrome选项有两个值,分别为true和false,默认为false,格式为monochrome=boolean。用来控制测试结果的可读性,当monochrome=true时,测试结果可读性更好。monochrome=true时,测试结果可读性比较差。
dryrun选项暂时不了解。
@CucumberOptions中的features,用于指定我们项目中要运行的feature的目录
@CucumberOptions中的plugin ,用于指定我们项目中要运行时生成的报告,并指定之后可以在target目录中找到对应的测试报告
@CucumberOptions中的glue,用于指定项目运行时查找实现step定义文件的目录几点
@CucumberOptions中的tags,用来决定想要Cucumber执行哪个特定标签(以及场景),标签以“@”开头
在实际项目中,一个测试工程可能由多个feature文件组成,并且每个feature文件中可能也是由多个scenario组成。默认情况下,每次运行是运行所有feature中的所有scenario。这样可能导致正常情况下运行一次测试脚本,需要非常长的时间来等待测试结果。
但实际过程中,测试用例是有优先级等区分的,比如smokeTest(冒烟)、regressionTest(回归)等
Tags的标记规则:
tags = {"@st"}, 表示只执行有@st标记的scenario
tags = {"@st","@dt"}, 表示只执行同时含有@st和@dt标记的scenario
tags = {"@st","~@dt"}, 表示执行有@st标记的同时排除标记有@dt标记的scenario
tags = {"@st,@dt"}, 表示执行有@st和@dt标记的scenario
//cucumber可以通过添加插件生成json或者html的报告。使用方法很简单,在@CucumberOptions的plugin里添加"html:target/cucumber"或者"json:target/cucumber.json",
// cucumber运行结果后会在对应的目录下生成html报告或者json文件。路径可自行修改。
网友评论