Implementing Traits in custom Visual Studio Test Adapters

Implementing Traits in custom Visual Studio Test Adapters

  • Comments 2

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.


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.


Leave a Comment
  • Please add 8 and 8 and type the answer here:
  • Post
  • Mathew, your job is amazing. I've been following your work since I started implementing XML Test Adapter. So now the most important question is, if you added Traits successfully, how can we add the ErrorMessage attribute is the test fails? can we do something about it?

  • @Akram,

    In the ITestExecutor.RunTests method, you can provide additional error information in the Test Result class.

    In my sample (, I have filled TestResult.Outcome. You can include additional information such as ErrorMessage & ErrorStackTrace.

Page 1 of 1 (2 items)