如何在不删除功能的情况下禁用specflow(Gherkin)中的功能?

时间:2010-06-03 13:44:13

标签: cucumber specflow gherkin

我有一些SpecFlow功能(使用Gherkin语法),我想暂时禁用该功能以防止其测试运行?

是否有可以标记该功能的属性来执行此操作?我猜测适用于Cucumber的东西也可能适用于SpecFlow。

4 个答案:

答案 0 :(得分:92)

您可以使用标记@ignore标记该功能:

@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'

答案 1 :(得分:10)

在Specflow的最新版本中,您现在还必须提供标记的原因,如下所示:

@ignore("reason for ignoring")

编辑:出于某种原因,它打破了空格,但这有效:

@ignore("reason")

答案 2 :(得分:2)

正如jbandi建议你可以使用@ignore标签。

标签可以应用于:

  • 单一场景
  • 完整功能

将NUnit作为测试提供者,生成代码的结果是插入

  

[NUnit.Framework.IgnoreAttribute()]

到方法或类。

答案 3 :(得分:2)

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     |

将上述视为特征文件&#34; CheckSample.feature&#34;

以下是您的步骤文件,它只是部分文件:

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);
   }

  }

重要的是要注意,&#34; @ ignored&#34;使用in&#34; junittestone&#34;在CucumberOptions(tags)中提到了特征文件中的文本。类文件。此外,请确保您的项目中有黄瓜,小黄瓜,Junit和其他罐子的所有相关jar文件,并且您已在步骤定义(类)中导入它们。

由于&#34;忽略&#34;,在执行测试时将跳过该场景。

相关问题