Terje Sandstrom has written two excellent blogs on using Traits in Visual Studio 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.
I modified XMLTestDiscoverer.GetTests to retrieve the category attribute from the XML and add it to the Traits property of the test case.
Now when I open the Test Explorer and the text xml file, I see
Super easy. Wasn’t it?
A tip from Terje in this context: Reflection/expression trees must be used to access the Traits property if one wants to be version independent.
With Visual Studio 2012 Update 1, we have implemented traits for all out-of-the-box test adapters. These include unit tests for
· C# Desktop
· C++ Native
· C# Windows Store
· C++ Windows Store
· Managed C++
Here is a screenshot of some of the Traits supported by out-of-the-box adapters.