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

我可以标记该功能的属性吗?我猜想与黄瓜一起使用的东西也可能与SpecFlow一起使用。

有帮助吗?

解决方案

您可以用标签@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'

其他提示

在最近版本的SpecFlow中,您现在还必须提供标签的原因,例如:

@ignore("reason for ignoring")

编辑:由于某种原因,它随空格而破裂,但这有效:

@ignore("reason")

正如Jbandi所建议的那样,您可以使用@ignore标签。

标签可以应用于:

  • 一个场景
  • 完整的功能

鉴于Nunit作为测试提供商,生成的代码的结果是插入

nunit.framework.ignoreattribute()

到该方法或类。

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

  }

重要的是要注意,在“ junittestone”类文件中,在Cucumberoptions(标签)中提到了功能文件中的“ @ignored”文本。另外,请确保您的项目中可用的Cucumber,Gherkin,Junit和其他JARS都有所有相关的JAR文件,并且您已在步骤定义(类)中导入它们。

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top