Implementing Traits in custom Visual Studio Test Adapters

Mathew Aniyan MSFT

Terje Sandstrom has written two excellent blogs on using Traits in Visual Studio Test Explorer.

How to manage unit tests in Visual Studio 2012 Update 1 : Part 1–Using Traits in the Unit Test Explorer

Part 2–Using Traits with different test frameworks in the Unit Test Explorer

In this blog, I will describe how you can implement Traits support for a custom Test adapter. [NOTE: This feature is only available in Visual Studio 2012 Update 1] I will use the XML Test Adapter that I had created in this blog. I will add a category attribute for each test case.

My test xml file looks like this now.

image

I modified XMLTestDiscoverer.GetTests to retrieve the category attribute from the XML and add it to the Traits property of the test case.

image

<p>Now when I open the Test Explorer and the text xml file, I see</p>  <p><a href="https://devblogs.microsoft.com/00/00/00/45/92/metablogapi/2110.image_2F22AE83.png"><img title="image" style="border-top: 0px;border-right: 0px;border-bottom: 0px;padding-top: 0px;padding-left: 0px;border-left: 0px;padding-right: 0px" border="0" alt="image" src="https://devblogs.microsoft.com/devops/wp-content/uploads/sites/6/2012/12/6327.image_thumb_54AC2BE4.png" width="302" height="138" /></a></p>  <p>Super easy. Wasn’t it?</p>  <p><u>A tip from Terje in this context</u>: Reflection/expression trees must be used to access the Traits property if one wants to be version independent. </p>  <p>&#160;</p>  <p>With Visual Studio 2012 Update 1, we have implemented traits for all out-of-the-box test adapters. These include unit tests for</p>  <p>· C# Desktop</p>  <p>· C++ Native</p>  <p>· C# Windows Store</p>  <p>· C++ Windows Store</p>  <p>· Managed C++</p>  <p>Here is a screenshot of some of the Traits supported by out-of-the-box adapters. </p>  <p><a href="https://devblogs.microsoft.com/00/00/00/45/92/metablogapi/2502.image_39FF8FCB.png"><img title="image" style="border-top: 0px;border-right: 0px;border-bottom: 0px;padding-top: 0px;padding-left: 0px;border-left: 0px;padding-right: 0px" border="0" alt="image" src="https://devblogs.microsoft.com/devops/wp-content/uploads/sites/6/2012/12/5314.image_thumb_62BAF514.png" width="774" height="345" /></a></p>

0 comments

Discussion is closed.

Feedback usabilla icon