How To: Get the Test Case associated with the unit test?


For running and managing unit tests using Microsoft Test Manager (MTM), the users have to do tcm testcase /import of the test assembly.  This step creates a test case work item corresponding to unit test on the client side.  With this, users can do many new scenarios – most importantly start viewing the history/trend of the result.

A FAQ that I have heard many times in internal and external forums is around this is –

Q: How to determine programmatically retrieve the test case artifact corresponding to this unit test?

A: Because of various reasons (legacy, loose coupling, extensibility etc), the unit test does not have any direct reference to the test case artifact.  However, one can get the corresponding test case artifact easily with few lines of code –

To compile the above code, you will need reference to following dll (and include namespaces appropriately) –


– Gautam



No Comments.