如何禁用 specflow (Gherkin)中的特性而不删除该特性?

我有一些 SpecFlow 特性(使用 Gherkin 语法) ,我想暂时禁用这个特性,以防止它的测试运行?

是否有一个属性我可以标记的功能,以做到这一点?我猜用于黄瓜的东西也可以用于 SpecFlow。

47668 次浏览

你可以用“忽略”标记这个特性:

@ignore @web
Scenario: Title should be matched
When I perform a simple search on 'Domain'
Then the book list should exactly contain book 'Domain Driven Design'

正如 jbandi 建议的那样,您可以使用“忽略”标记。

标签可应用于:

  • 一个单一的场景
  • 一个完整的特征

如果给定 NUnit 作为测试提供程序,则生成的代码中的结果是插入

[ NUnit. Framework. IgnoreAttribute ()]

方法或类。

在最近的 Specflow 版本中,你还需要提供一个标签的理由,比如:

@ignore("reason for ignoring")

编辑: 由于某种原因,它与空格断开,但这个可以:

@ignore("reason")
Feature: CheckSample


@ignored
Scenario Outline: check ABC    #checkout.feature:2
Given I open the applciation
When I enter username as "<username>"
And I enter password as "<password>"
Then I enter title as "<title>"
Examples:
| username | password |
| dude     | daad     |

考虑上面的特性文件“ CheckSample.Feature”

下面是你的步骤文件,它只是部分文件:

public class Sampletest {




@Given("^I open the applciation$")
public void i_open_the_applciation() throws Throwable {
// Write code here that turns the phrase above into concrete actions
//throw new PendingException();
}

下面是运行文件:

@RunWith(Cucumber.class)
@CucumberOptions(
plugin = {"pretty", "html:target/reports",
"json:target/reports/cucumber-report.json"},
monochrome = true,
tags = {"~@ignored"}
)


public class junittestOne {


public static void main(String[] args) {
JUnitCore junit = new JUnitCore();
Result result = junit.run(junittestOne.class);
}


}

这里需要注意的是,特性文件中的“@忽略”文本在 CucumberOptions (标记)中与“ junittestone”类文件中提到。另外,确保您的项目中有所有与黄瓜、小黄瓜、 Junit 和其他罐子相关的 jar 文件,并且您已经在步骤定义(类)中导入了它们。

由于“忽略”,在执行测试时将跳过该场景。