MSTest

SpecFlow does support MsTest V2. It is not any more working with the old MsTest V1.

Documentation for MSTest can be found here.

Needed NuGet Packages

For SpecFlow: SpecFlow.MSTest

For MSTest: MSTest.TestFramework

For Test Discovery & Execution:

Accessing TestContext

using Microsoft.VisualStudio.TestTools.UnitTesting;

public class MyStepDefs
{
    private readonly TestContext _testContext;
    public MyStepDefs(TestContext testContext) // use it as ctor parameter
    { 
        _testContext = testContext;
    }

    [BeforeScenario()]
    public void BeforeScenario()
    {
        //now you can access the TestContext
    } 
}

Tags for TestClass Attributes

The MsTest Generator can generate test class attributes from tags specified on a feature.

Owner

Tag:

@Owner:John

Output:

[Microsoft.VisualStudio.TestTools.UnitTesting.OwnerAttribute("John")]

WorkItem

Tag:

@WorkItem:123

Output:

[Microsoft.VisualStudio.TestTools.UnitTesting.WorkItemAttribute(123)]

DeploymentItem

Example 1 : Copy a file to the same directory as the deployed test assemblies

Tag:

@MsTest:DeploymentItem:test.txt

Output:

[Microsoft.VisualStudio.TestTools.UnitTesting.DeploymentItemAttribute("test.txt")]

Example 2 : Copy a file to a sub-directory relative to the deployment directory

Tag:

@MsTest:DeploymentItem:Resources\DeploymentItemTestFile.txt:Data

Output:

[Microsoft.VisualStudio.TestTools.UnitTesting.DeploymentItemAttribute("Resources\\DeploymentItemTestFile.txt", "Data")]