Learn to use Visual Studio, Visual Studio Online, Application Insights and Team
Foundation Server to decrease rework, increase transparency into your application and increase the rate at which
you can ship high quality software throughout the application lifecycle
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.
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?
In the ITestExecutor.RunTests method, you can provide additional error information in the Test Result class.
In my sample (blogs.msdn.com/.../writing-a-visual-studio-2012-unit-test-adapter.aspx), I have filled TestResult.Outcome. You can include additional information such as ErrorMessage & ErrorStackTrace.