{"id":3823,"date":"2012-12-04T19:45:58","date_gmt":"2012-12-04T19:45:58","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/visualstudioalm\/2012\/12\/04\/implementing-traits-in-custom-visual-studio-test-adapters\/"},"modified":"2019-02-14T17:57:51","modified_gmt":"2019-02-15T01:57:51","slug":"implementing-traits-in-custom-visual-studio-test-adapters","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/devops\/implementing-traits-in-custom-visual-studio-test-adapters\/","title":{"rendered":"Implementing Traits in custom Visual Studio Test Adapters"},"content":{"rendered":"<p><a href=\"http:\/\/geekswithblogs.net\/terje\/Default.aspx\">Terje Sandstrom<\/a> has written two excellent blogs on using Traits in Visual Studio Test Explorer.<\/p>\n<p><a href=\"http:\/\/blogs.msdn.com\/b\/visualstudioalm\/archive\/2012\/11\/09\/how-to-manage-unit-tests-in-visual-studio-2012-update-1-part-1-using-traits-in-the-unit-test-explorer.aspx\">How to manage unit tests in Visual Studio 2012 Update 1 : Part 1\u2013Using Traits in the Unit Test Explorer<\/a><\/p>\n<p><a href=\"http:\/\/blogs.msdn.com\/b\/visualstudioalm\/archive\/2012\/11\/20\/part-2-using-traits-with-different-test-frameworks-in-the-unit-test-explorer.aspx\">Part 2\u2013Using Traits with different test frameworks in the Unit Test Explorer<\/a><\/p>\n<p>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 <a href=\"http:\/\/blogs.msdn.com\/b\/visualstudioalm\/archive\/2012\/07\/31\/writing-a-visual-studio-2012-unit-test-adapter.aspx\">blog<\/a>. I will add a category attribute for each test case.<\/p>\n<p>My test xml file looks like this now.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/00\/00\/00\/45\/92\/metablogapi\/5611.image_1D564083.png\"><img decoding=\"async\" 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\/2475.image_thumb_3BC0816C.png\" width=\"411\" height=\"87\" \/><\/a><\/p>\n<p>I modified XMLTestDiscoverer.GetTests to retrieve the category attribute from the XML and add it to the Traits property of the test case.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/00\/00\/00\/45\/92\/metablogapi\/4201.image_0C2262E0.png\"><img decoding=\"async\" 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=\"\" width=\"547\" height=\"99\" \/><\/a><\/p>\n<pre><code>&lt;p&gt;Now when I open the Test Explorer and the text xml file, I see&lt;\/p&gt;  &lt;p&gt;&lt;a href=\"https:\/\/devblogs.microsoft.com\/00\/00\/00\/45\/92\/metablogapi\/2110.image_2F22AE83.png\"&gt;&lt;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\" \/&gt;&lt;\/a&gt;&lt;\/p&gt;  &lt;p&gt;Super easy. Wasn\u2019t it?&lt;\/p&gt;  &lt;p&gt;&lt;u&gt;A tip from Terje in this context&lt;\/u&gt;: Reflection\/expression trees must be used to access the Traits property if one wants to be version independent. &lt;\/p&gt;  &lt;p&gt;&amp;#160;&lt;\/p&gt;  &lt;p&gt;With Visual Studio 2012 Update 1, we have implemented traits for all out-of-the-box test adapters. These include unit tests for&lt;\/p&gt;  &lt;p&gt;\u00b7 C# Desktop&lt;\/p&gt;  &lt;p&gt;\u00b7 C++ Native&lt;\/p&gt;  &lt;p&gt;\u00b7 C# Windows Store&lt;\/p&gt;  &lt;p&gt;\u00b7 C++ Windows Store&lt;\/p&gt;  &lt;p&gt;\u00b7 Managed C++&lt;\/p&gt;  &lt;p&gt;Here is a screenshot of some of the Traits supported by out-of-the-box adapters. &lt;\/p&gt;  &lt;p&gt;&lt;a href=\"https:\/\/devblogs.microsoft.com\/00\/00\/00\/45\/92\/metablogapi\/2502.image_39FF8FCB.png\"&gt;&lt;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\" \/&gt;&lt;\/a&gt;&lt;\/p&gt;\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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\u2013Using Traits in the Unit Test Explorer Part 2\u2013Using Traits with different test frameworks in the Unit Test Explorer In this blog, I will describe how you [&hellip;]<\/p>\n","protected":false},"author":98,"featured_media":45953,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3823","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops"],"acf":[],"blog_post_summary":"<p>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\u2013Using Traits in the Unit Test Explorer Part 2\u2013Using Traits with different test frameworks in the Unit Test Explorer In this blog, I will describe how you [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/3823","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/users\/98"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/comments?post=3823"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/3823\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media\/45953"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media?parent=3823"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/categories?post=3823"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/tags?post=3823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}