Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 952
Greg Burghardt Avatar asked Dec 16 '13 14:12

Greg Burghardt


People also ask

How run SpecFlow test cases from command line?

You can run SpecFlow+ tests from the command line, either using SpecRun.exe (Full Framework) or dotnet test or vstest. console.exe (. NET Core).

How do I run a specific scenario in SpecFlow?

In order to execute your SpecFlow tests, you need to define the tests as Gherkin feature files, bind the steps defined in your feature files to your code, and configure a unit test provider to execute the tests. SpecFlow generates executable unit tests from your Gherkin files.

How do I run a SpecFlow feature file in Visual Studio?

when right-clicking on a feature file and selecting Run Custom Tool , make sure the SpecFlow extension is enabled. To enable the extension in Visual Studio, select Tools | Extensions and Updates…, select the “SpecFlow for Visual Studio” extension, then select Enable.


1 Answers

Now that SpecFlow 3.0 has been released we can use SpecFlow with .NET Core. The CLI tool for .NET Core is dotnet and tests are run like this if you use MSTest (vstest):

dotnet test

If the tests are in a specific project you can specify the project like this

dotnet test TestProject

where TestProject is the name of the project. You can skip the project name if you want to, but specifying it will make dotnet look in only that project. To list all the tests in the project you can use the -t flag:

dotnet test TestProject -t

To run only specific tests you can use the --filter flag:

dotnet test TestProject --filter ShouldBeSuccess_1

where ShouldBeSuccess_1 is the name of the test. The argument after --filter is an expression, and not necessary the name of the test If you had a test called ShouldBeSuccess_12 it would also run. You can see the rules for --filter here.

To only run the tests in a specific category you can use TestCategory:

dotnet test TestProject --filter TestCategory=ci

where ci is the category name. To add a test to a category you use tags.

To create the results file you have to use the --logger flag:

dotnet test TestProject --logger trx

Here it's used to create a trx results file.

like image 199
Mika Sundland Avatar answered Oct 19 '22 20:10

Mika Sundland