How do I disable a feature in specflow (Gherkin) without deleting the feature?
Asked Answered
S

5

79

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.

Sixtasixteen answered 3/6, 2010 at 13:44 Comment(0)
L
114

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'
Lifeboat answered 3/6, 2010 at 14:7 Comment(6)
Cool, is there anywhere I can find a list of attributes?Sixtasixteen
We are talking about tags here. @ignore is the only "predefined" tag. Else tags can be freely defined to control the Before-/After-Hooks and to selectively run features.Lifeboat
I'd look at the code of the generator since it provides the most accurate answer: github.com/techtalk/SpecFlow/blob/master/Generator/… There's also the SpecFlow changelog github.com/techtalk/SpecFlow/blob/master/changelog.txt and I'll quote: "MsTest: Support for MSTest's [Owner] and [WorkItem] attributes with tags like \@owner:foo \@workitem:123 (Issue 162, Pull 161)" However, the list of attributes kind of depends on the test framework and test runner you're using along with SpecFlow :)Eyler
I have found that the @ignore attribute needs to be added to every single Scenario within a feature.Gamin
@Gamin you should be able to mark the whole feature as @ignoreEngulf
what happens when we run the test case maked as @ignore in an Azure pipeline? Would that test case be marked as <b>fail</b> or would not be even considered in the pipeline runBernetta
A
19

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")
Afb answered 4/5, 2016 at 21:3 Comment(0)
H
3

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.

Houselights answered 18/10, 2013 at 12:15 Comment(0)
R
1
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.

Rejoin answered 1/6, 2017 at 15:55 Comment(1)
has to be ﹫ignore and not ﹫ignored or it wont be ignored. Sorry, not sure how to write the AT-symbol here.Gilmour
P
0

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

Peddada answered 1/6, 2023 at 15:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.