How to retrieve the ID of the workitem that started an automated test

流过昼夜 提交于 2019-12-10 11:42:07

问题


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:


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.



来源:https://stackoverflow.com/questions/17995330/how-to-retrieve-the-id-of-the-workitem-that-started-an-automated-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!