1

Introduction:
In VS2012, we have a set of workitems that are planned to be automated. I created a set of automated tests through SpecFlow in VS2010. To connect a workitem with an automated test, I have to select the workitem and search for the automated test that can only be exactly one method.

The drawback is that with a large amount of TestMethods (and we have), the list is very long. It will be a tedious task to connect a WorkItem with the corresponding TestMethod. Thereby, lots of our tests (and therefore the TestMethod names) are generated automatically because we use SpecFlow. And when a teammember change the name of the scenario, this TestMethod name is also changed, breaking the connection between the WorkItem and the automated test.

What I want:
I want to create a single TestMethod that can be selected for each automated workitem. This TestMethod retrieves the workitem ID and searches for a TestMethod that starts with that ID, or has a SpecFlow Tag attribute with that ID. Therefore I need the ID of the workitem.

Question:
How do I retrieve the ID of the workitem that initiated the test?

1 Answer 1

4

I found the solution for retrieving the test case ID for a workitem in TFS for tests that are executed by Microsoft Test Manager:

string tcId = TestContext.Properties["__Tfs_TestCaseId__"].ToString();

Provided that this method is in a TestClass object. A TestClass object automatically gets a TestContext instance. MTM is using the TestContext to serve information to the TestMethod it is running.

A full list of the (undocumented) properties can be found on the blog of InfoSupport.

3
  • This is a LIFESAVER for us... Don't have enough up-votes for this :-) Thank you very much for supplying a solution here. All the potential workarounds are fragile and crap, quite frankly. Dec 18, 2013 at 15:18
  • Anyway you could provide details on what you did in that single test method to search to tests that have the specflow tag of the workitem. That would be really helpful to see! Jan 18, 2014 at 18:38
  • @MarkLindell Unfortunately it didn't work out as I hoped for; I could retrieve the SpecFlow scenario and its mapped testmethod with the use of reflection, but you cannot just call that method. You must assign a testrunner that will run that specific method and I couldn't manage that yet. Because of shifting priorities and for the testers a sufficient work around I didn't put more effort in it to figure out how to get it running. Maybe later because I have another project with exact the same demands. Feb 28, 2014 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.