Using the MsTest TestContext with SpecFlow

669 views
Skip to first unread message

Jonathan Dodds

unread,
Jun 9, 2015, 3:38:54 AM6/9/15
to spec...@googlegroups.com
Hi,
What are people's thoughts on supporting the MsTest TestContext object in SpecFlow?


To get a TestContext for use in TestMethods, a class that is decorated with the TestClass attribute must have a public non-static TestContext property, such as follows:

public TestContext TestContext { get; set; }

The test runner calls the setter. Your own code in the TestMethods should only be using the getter. Also a TestContext is passed to the AssemblyInitialize and ClassInitialize methods.

The TestContext object isn't for sharing information across methods of the TestClass so it's not like SpecFlow's FeatureContext and ScenarioContext.

The TestContext's usefulness is very limited but it does provide potentially valuable information. For example, the TestContext has a DeploymentDirectory property. The directory location of the test could be discovered in other ways but it would be far more convenient to just have what the test runner and test framework provide.

When the test provider is MsTest, should the TestContext be exposed or its information be added to the FeatureContext?

Thanks

Sam Holder

unread,
Jun 9, 2015, 5:47:49 AM6/9/15
to specflow
I believe this has been discussed before and rejected as no good way to get access to the test context in a provider agnostic way could be seen. ie what do you do if the provider is not MSTest? Have null properties? Really the information required from the test context should be added to the specflow context regardless of the provider used.

As always though Pull Requests are king, so if you want to implement this it might be considered. What other than the deployement directory do you want to get access to? I use MSTest and have never needed the deployment directory (I sometimes have to add [DeploymentItem] attributes to the specflow features, but have never needed the deployment directory directly) or the test context.

Sam

--
You received this message because you are subscribed to the Google Groups "SpecFlow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to specflow+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages