I'm currently refactoring a medium size application due to some terminology changes in the business terms. We have around 121 SpecFlow feature files that would need to be changed.
I like how you can "deprecate" an API in C#, first as warnings:
[Obsolete("Use MyClass.NewMethod instead")]
public void OldMethod() { }
Then compiler errors:
[Obsolete("Use MyClass.NewMethod instead", true)]
public void OldMethod() { }
It would be nice to have this sort of functionality for SpecFlow steps:
[When("I old foo", Obsolete = true)]
[When("I new foo")]
public void WhenIFoo() { }
Is there any way to mark steps in SpecFlow as obsolete so other developers know the steps need to be changed in their Feature files, but not prevent them from authoring and running tests? And as an added bonus, Is there a way to optionally cause compiler or test run failures?
Starting with version v2.4, SpecFlow respects [Obsolete]
attributes on step bindings.
For your example you would probably use it like this:
[When("I old foo")]
[Obsolete("you should use WhenIFoo instead")]
public void WhenIOldFoo() { }
[When("I new foo")]
public void WhenIFoo() { }
As the default behavior for using such steps a warning is issued. Utilizing the obsoleteBehavior
attribute on SpecFlow's <runtime>
configuration, you can change that, esp. failing test execution:
<specFlow>
...
<runtime obsoleteBehavior="Error" />
</specFlow>
In the meantime the Wiki-page for the Configuration has been updated to document that feature.