MSTest¶
Reqnroll supports MsTest V2 or later (NuGet Version 2.2.8 or higher).
Note
MsTest V4 is supported from Reqnroll v3.2 onwards.
Documentation for MSTest can be found here.
Needed NuGet Packages¶
For Reqnroll: Reqnroll.MSTest
For MSTest: MSTest.TestFramework
For Test Discovery & Execution:
Accessing TestContext¶
You can access the MsTest TestContext instance in your step definition or hook classes by constructor injection:
using Microsoft.VisualStudio.TestTools.UnitTesting;
[Binding]
public class MyStepDefs
{
private readonly TestContext _testContext;
public MyStepDefs(TestContext testContext) // use it as ctor parameter
{
_testContext = testContext;
}
[Given("a step")]
public void GivenAStep()
{
//you can access the TestContext injected in the ctor
_testContext.WriteLine(_testContext.TestRunDirectory);
}
[BeforeScenario()]
public void BeforeScenario()
{
//you can access the TestContext injected in the ctor
_testContext.WriteLine(_testContext.TestRunDirectory);
}
}
In the static BeforeTestRun/AfterTestRun hooks you can use parameter injection:
using Microsoft.VisualStudio.TestTools.UnitTesting;
[Binding]
public class Hooks
{
[BeforeTestRun]
public static void BeforeTestRun(TestContext testContext)
{
//you can access the TestContext injected as parameter
testContext.WriteLine(testContext.TestRunDirectory);
}
[AfterTestRun]
public static void AfterTestRun(TestContext testContext)
{
//you can access the TestContext injected as parameter
testContext.WriteLine(testContext.DeploymentDirectory);
}
}