代码之家  ›  专栏  ›  技术社区  ›  Simon Keep

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

  •  60
  • Simon Keep  · 技术社区  · 15 年前

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

    有没有一个属性可以用来标记功能?我猜对Cucumber有效的东西也可能对SpecFlow有效。

    4 回复  |  直到 15 年前
        1
  •  103
  •   jbandi    15 年前

    您可以使用标记@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'
    
        2
  •  14
  •   Xena    9 年前

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

    @ignore("reason for ignoring")
    

    @ignore("reason")
    
        3
  •  2
  •   Be.St.    11 年前

    正如jbandi建议的那样,可以使用@ignore标记。

    标记可应用于:

    • 单一场景
    • 全功能

    方法或类。

        4
  •  1
  •   MKod    8 年前
    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     |
    

    下面是您的step文件,它只是部分文件:

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

    需要注意的是,功能文件中的“@ignored”文本在CucumberOptions(标记)中提到,在“junitestone”类文件中提到。另外,确保项目中有cucumber、gherkin、Junit和其他jar的所有相关jar文件,并且已经将它们导入step定义(类)中。

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