Greg Burghardt Greg Burghardt - 1 year ago 737
C# Question

How do you run SpecFlow scenarios from the command line using MSTest?

I've got Visual Studio 2010, and we have two VS solutions we work with. The first is the web application, and the second is strictly for SpecFlow tests. Having two instances of Visual Studio running at the same time just to run SpecFlow features is eating all the available RAM causing things to slow down.

I've done some searching on Google and here on StackOverflow, plus perused the MS documentation on the MSTest command line tool, but I haven't found the answer. The full SpecFlow test suite takes ~45 minutes to complete, and I really only need to run a few scenarios.

I was wondering if there is a way to run individual SpecFlow features, and even individual scenarios, from the command line using MSTest?

Answer Source

Behind the scene specflow tests are just regular mstest unit tests. So you should be able to run them the same way using something like:

To run a specific scenario:

mstest /testcontainer:tests.dll /test:GivenMyScenarioWhenIDoSomeStuff

To run a several specific scenario you can use the /test flag multiple times:

mstest /testcontainer:tests.dll /test:GivenMyScenarioWhenIDoSomeStuff /test:GivenMyScenarioWhenIDoSomemthingElse

To run a feature

mstest /testcontainer:tests.dll /test:MyFeatureName

If you add tags on your scenarios using @MyTag for example, you could also use the option

/category:MyTag to filter down the scenarios to run.

Please have a look to the generated code behind of your feature files to get a clue of how things actually work, if you are familliar with mstest it should be pretty straightforward.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download