English 中文(简体)
How do I disable a feature in specflow (Gherkin) without deleting the feature?
原标题:

I have some SpecFlow features (using the Gherkin syntax) and I would like to temporarily disable the feature to prevent its tests from running?

Is there an attribute I can mark the feature with to do this? I m guessing that something that works with Cucumber might also work with SpecFlow.

最佳回答

You can mark the feature with the tag @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 
问题回答

In the recent version of Specflow, you now also have to provide a reason with the tag, like so:

@ignore("reason for ignoring")

EDIT: For some reason it break with spaces but this works:

@ignore("reason")

As jbandi suggests you can use the @ignore tag.

Tag can be applied to:

  • a single Scenario
  • a full Feature

Given NUnit as the test provider, the result in generated code is the insertion of the

[NUnit.Framework.IgnoreAttribute()]

to the method or the class.

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     |

consider the above as feature file "CheckSample.feature"

And below is your step file, it is just partial file:

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

Now below will be runner file:

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

  }

Important to note here, the "@ignored" text in feature file is mentioned in CucumberOptions (tags) with in "junittestone" class file. Also, make sure you have all relevant jar files for both cucumber, gherkin, Junit and other jars available in your project and you have imported them in your step definitions (class).

Because of "ignored", the scenario will be skipped while executing tests.

The feature file you do not want to run, write @smoke before Scenario. Then, in the Runner file, write tag = "not @smoke" . You will run all feature files but the one you indicated as @smoke





相关问题
Why Cucumber hook methods aren t lowercase?

Cucumber has a few different hook methods like Before, After or AfterStep. I was wondering - why doesn t these method names follow Ruby s naming conventions to write method names all lowercase? ...

Cucumber Table Diff and colspan

I love cucumber, and its table diff feature. But I, often use a td colspan to display the title of the table. And I can t seem to get the table diff to work when I use colspan. (Table diff expects a ...

cucumber features --guess

I m setting up my Authlogic user session features. And I m in some kind of confusion. When I run: cucumber features I get some red errors Scenario: User signs in successfully ...

Rails | Cucumber | acl9 | AccessDenied

I am ramping up Cucumber, and I am having a issue getting one of my first tests to pass. The exception I am getting is: And I visit the new contract screen Acl9::AccessDenied (Acl9::AccessDenied) ...

Silencing Factory Girl logging

Just to clear the air, I am not some cruel factory master trying to silence working ladies. I am having a very annoying problem where when using Thoughtbot s factory girl in my specs, every time ...

How to resolve Rails model namespace collision

The story so far: I have a rails app with a model named "Term". All is well until trying to install Cucumber. Upon running rake cucumber I get Term is not a class (TypeError) This happens because ...

rspec testing views with internationalization?

I want to make sure I have the right meta desc/keyword and title text in my view so I want to create rspec views tests for that. Now the real challange here is how to make it work across multiple ...

热门标签