Generate steps in vscode
SpecFlow Version:
- [x ] 3.1
- [ ] 3.0
- [ ] 2.4
- [ ] 2.3
- [ ] 2.2
- [ ] 2.1
- [ ] 2.0
- [ ] 1.9
Used Test Runner
- [ ] SpecFlow+Runner
- [x ] MSTest
- [x ] NUnit
- [ ] Xunit
More of a question than an issue. Do you have any plans to add an option to generate steps file in VS Code / do you suggest a best way to generate steps files automatically in vs code ? Thanks, Rahul.
We are building Labs around .NET Core, SpecFlow, and VS Code. We are blocked trying to figure out how to generate the steps files. We are not using Visual Studio proper.
Thank you
See cucumber-autocomplete extension
On Wed, 13 May 2020 at 19:17 Doug Finke [email protected] wrote:
We are building Labs around .NET Core, SpecFlow, and VS Code. We are blocked trying to figure out how to generate the steps files. We are not using Visual Studio proper.
Thank you
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/SpecFlowOSS/SpecFlow/issues/1960#issuecomment-628096387, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB3OII4ZFRT76M54UHPTKZDRRLB3HANCNFSM4MSCHCBQ .
-- Best Regards, Gennady Verdel
This looks like it only handles snippets in the vs code editor.
Does this also generate the *steps.cs at build time?
Thank you
Found a work around. If you run tests on a feature file, it generates errors with all method names and missing steps. Log that into a file and generate a class from that.
We don't have yet any extensions for VS Code, but you can get already the binding skeleton code. When SpecFlow doesn't find any bindings, it is writing this to the test output.
Here is an example:
Error Message:
TechTalk.SpecFlow.xUnit.SpecFlowPlugin.XUnitPendingStepException : Test pending: No matching step definition found for one or more steps.
using System;
namespace MyNamespace
{
[Binding]
public class StepDefinitions
{
private readonly ScenarioContext _scenarioContext;
public StepDefinitions(ScenarioContext scenarioContext)
{
_scenarioContext = scenarioContext;
}
[When(@"I write scenarios")]
public void WhenIWriteScenarios()
{
_scenarioContext.Pending();
}
}
}
Stack Trace:
at TechTalk.SpecFlow.xUnit.SpecFlowPlugin.XUnitRuntimeProvider.TestPending(String message)
at TechTalk.SpecFlow.ErrorHandling.ErrorProvider.ThrowPendingError(ScenarioExecutionStatus testStatus, String message)
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnAfterLastStep()
at TechTalk.SpecFlow.TestRunner.CollectScenarioErrors()
at TestProject.Features.UsingVSCodeAndSpecFlowFeature.ScenarioCleanup()
at TestProject.Features.UsingVSCodeAndSpecFlowFeature.IWantToWriteScenariosInVSCodeWithoutExtensions() in
You can simply copy this code in your classes.
@dfinke
What do you mean with Does this also generate the *steps.cs at build time? exactly?
There are no Steps.cs files that are generated at build time at all.
The Feature- Codebehind- Files (.feature.cs) are created at build time by the SpecFlow.Tools.MSBuild.Generation- package.
Thank you @SabotageAndi
I don't get that error outputted though.
I'm using .NET Core 2.1.504, the SpecFlow Calculator example
I use dotnet build and dotnet test. I deleted the CalculatorSteps.cs, but that error and output do not get outputted. I'm running it on Linux.
I only get this:
Starting test execution, please wait...
Not Run AddTwoNumbers
@dfinke Interesting. I tried it now with .NET Core 3.0/3.1 in WSL. This is my output:

Perhaps they changed the output detail information. Try to do a dotnet test -v normal or dotnet test -v detailed.
Thank you. Yeah, I tried the -v option, no go. Is that skeleton generated based on the feature.cs? Or just generic?
Maybe you need a specflow.json file with this setting ?
{ "runtime": { "missingOrPendingStepsOutcome": "Error" } }
Thanks, no, didn't work, including the verbose options
specflow.json isn't needed for this. In my example, I don't have anything.
The skeleton is generated based on which binding is executed. That this is possible at all, you need the feature.cs files. But that is working for you, because if not, you wouldn't have the test at all.
Ok, found the issue. My example is using xUnit. If I use NUnit I also don't have the output.
Looks like the Assert.Inconclusive message is not written by the NUnit3TestAdapter.
See: https://github.com/SpecFlowOSS/SpecFlow/blob/master/Plugins/TechTalk.SpecFlow.NUnit.SpecFlowPlugin/NUnitRuntimeProvider.cs#L10
Hello @SabotageAndi I have recently developed an extension for generating the SpecFlow bindings in VS Code. I have added few additional features e.g. generating the complete class structure along with bindings and also an option to write directly to skeleton C# class file(s). Request you to take a look and help/suggest for some tips for known issues. https://marketplace.visualstudio.com/items?itemName=RajUppadhyay.specflow-steps-definition-generator
Thanks
@alimogithub & @JordanWestern could you have a look at this VSCode extension from @uppadhyayraj?
Thanks @uppadhyayraj for the info about your extension. It would be cool if somebody could adjust our VSCode documentation at https://github.com/SpecFlowOSS/SpecFlow/tree/master/docs/vscode.
And don't forget, also documentation changes are legitimate for the Community Heroes program!
Thanks much @SabotageAndi for reviewing and sharing next steps. @SabotageAndi and @alimogithub I have full documentation with setting up VSCode along with configuration here Please let me know if more details required from my side. Cheers Raj