As at the time of writing (November 2015), the SpecFlow for Visual Studio 2015
extension does not play well with DNX projects (.xproj
).
Wait for the VS extension to support DNX projects. In the meantime, I present...
Update your project.json
:
- Include
SpecFlow.Dnx
:
"dependencies": { "SpecFlow.Dnx": "1.0.0-*" }
- Add a command:
"commands": { "specflow-dnx": "SpecFlow.Dnx" }
- Add a
prebuild
script to call your command:
"scripts": { "prebuild": [ "dnx specflow-dnx" ] }
As of DNX RC1, you have to "produce outputs" to pipe the build through dnu
:
You can run manually with dnu build
(or just call dnx specflow-dnx
on it's own):
dnx451
dnx46
PR's to add support for other frameworks are welcome as long as they include an accompanying sample.
If you build the samples solution, you should see .feature.cs
files and an app.config
being generated.
The auto-generated app.config
is configured to use xUnit:
<unitTestProvider name="xUnit" />
This can be changed as per the SpecFlow Configuration Documentation, however (at time of writing) no other test frameworks are available for DNX.
xUnit has been updated to work both with DNX and the Visual Studio Test Explorer. In order to make your project compatible with Test Explorer, please follow these steps:
- Add a dependency to
xunit
. (At time of writing, version2.1.0
) - Add a dependency to
xunit.runner.dnx
. (At time of writing, version2.1.0-rc1-build204
) - Add a command to execute the xunit runner:
"test": "xunit.runner.dnx"
Note: It is important that the command used is "test". This is a convention used by Test Explorer, and will not work without it.
Here is a complete sample project.json
for reference:
{
"version": "1.0.0-*",
"dependencies": {
"SpecFlow.Dnx": "1.0.0-alpha8",
"xunit": "2.1.0",
"xunit.runner.dnx": "2.1.0-rc1-build204"
},
"commands": {
"create-specs": "SpecFlow.Dnx",
"test": "xunit.runner.dnx"
},
"scripts": {
"prebuild": "dnx create-specs"
},
"frameworks": {
"dnx46": { }
}
}
Examples in Test Explorer:
One of the nice features from the VS extension is being able to easily generate stubs for missing step definitions. This is still kind of possible, but definitely not as nice as the typical usage from the extension.
So, a feature file:
Build to generate the .feature.cs
file and run it:
Right-click and Copy All
:
Paste in your text editor of choice, then copy out the actual steps:
Given this should be a short-lived solution, hopefully this workaround is tolerable.
- SpecFlow Issue 471: Auto generation of
feature.cs
fails when using MSBuild that comes with VS2015 - SpecFlow Issue 457: SpecFlow "Generate Step Definition" context menu missing in VS2015
- SpecFlow Google Group discussing VS2015 & DNX