{"id":3903,"date":"2012-11-20T12:24:02","date_gmt":"2012-11-20T12:24:02","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/visualstudioalm\/2012\/11\/20\/part-2using-traits-with-different-test-frameworks-in-the-unit-test-explorer\/"},"modified":"2024-03-13T08:57:39","modified_gmt":"2024-03-13T16:57:39","slug":"part-2using-traits-with-different-test-frameworks-in-the-unit-test-explorer","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/devops\/part-2using-traits-with-different-test-frameworks-in-the-unit-test-explorer\/","title":{"rendered":"Part 2\u2013Using Traits with different test frameworks in the Unit Test Explorer"},"content":{"rendered":"<p>As promised one of the ALM MVPs, Terje Sandstrom, has delivered Part 2 of his Unit Test Series: \u201cUsing Traits with different test frameworks in the Unit Test Explorer\u201d.<\/p>\n<p>From the traffic and comments on his first post these are clearly very appreciated articles!<\/p>\n<p>Thanks Terje!<\/p>\n<p>\u00a0<\/p>\n<p>*********************************************************************************************************************************************\u2019<\/p>\n<p>In <a href=\"https:\/\/learn.microsoft.com\/en-us\/archive\/blogs\/visualstudioalmrangers\/\" target=\"_blank\" rel=\"noopener\"><u>Part 1<\/u><\/a>\u00a0 traits in general was described, and we used examples from using MSTest as a testing framework.\u00a0 In this part we will built upon what we did in Part 1, but extend it with many of the other frameworks.\u00a0 The Unit Test Explorer is test framework agnostic!\u00a0 It works with any framework, as long as there exist an adapter, and such adapters are coming for NUnit, XUnit, MBUnit, Javascript-Chutzpah, MS Native C++ and even more.\u00a0 A list of these and links to information and downloads for this can be found in<u> <\/u><a href=\"https:\/\/learn.microsoft.com\/en-us\/archive\/blogs\/visualstudioalmrangers\/\" target=\"_blank\" rel=\"noopener\"><u>this blog post<\/u><\/a>. Note that some of these are being updated along with the release of Update 1. See summary at the end of the blog post.<\/p>\n<p>The summary at the end also shows the syntax for the different traits in the different test frameworks.<\/p>\n<p>We will continue with the code examples from Part 1, and do something that perhaps is not so usual, mixing in some of the other frameworks and let them play together !\u00a0 That way it is also easier to see the differences between these.\u00a0 It will be done step by step, so the examples expand as we add more.\u00a0 The sequence is completely random and doesn\u2019t express any preferences.<\/p>\n<p>What is pretty cool, is that we show that in principle <strong>all types of tests can be run at the same time,<\/strong> many even in the same project, although Managed C++, Native C++ and Javascript tests stay in their own projects, but all in the same solution, and the results will be merged together in the Test Explorer !<\/p>\n<p>The different frameworks and their adapters are at somewhat different levels regarding how compliant they are to the new Trait system.\u00a0 Information is given for each framework on what is missing, and also expected time of arrival for the improvements where we have managed to obtain that information.<\/p>\n<p>\u00a0<\/p>\n<p><strong><font size=\"3\">Adding in <a href=\"http:\/\/www.nunit.org\/\" target=\"_blank\" rel=\"noopener\"><u>NUnit<\/u><\/a><\/font><\/strong><\/p>\n<p>Now let us mix in a NUnit Test first. In order to do this you must install the <a href=\"https:\/\/aka.ms\/nunit-vs11\" target=\"_blank\" rel=\"noopener\"><u>NUnit Test Adapter from Visual Studio Gallery<\/u><\/a>, and you must add a NUnit package from NuGet to your project. Adding the NuGet is done in a few steps as shown in the image series below.<\/p>\n<p>Step A: From Visual Studio Tools menu, choose Library Package Manager\/Manage NuGet Packages for Solution.<\/p>\n<p><a href=\"\/Users\/chass\/AppData\/Local\/Temp\/WindowsLiveWriter1560487288\/supfiles16D89AF\/image12.png\"><img decoding=\"async\" title=\"image_thumb4\" 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_thumb4\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/11\/8032.image_thumb4_21AF77C1.png\" width=\"244\" height=\"213\" \/><\/a><\/p>\n<p>Step B: If this is the first time you add this to any solution, choose Online, and add \u201cNUnit\u201d in the search box, select the NUnit. (Note, you don\u2019t need the NUnit.Runners, as VIsual Studio has its own runner that will run these for you). If you already have done this once, go instead to the Installed Packages, NUnit will be listed there and press the button \u201cManage\u201d. Any of these will take you to step \u2018C\u2019.<\/p>\n<p><a href=\"\/Users\/chass\/AppData\/Local\/Temp\/WindowsLiveWriter1560487288\/supfiles16D89AF\/image13.png\"><img decoding=\"async\" title=\"image_thumb5\" 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_thumb5\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/11\/7450.image_thumb5_28628144.png\" width=\"244\" height=\"112\" \/><\/a><\/p>\n<p>Step C: Choose the test projects where you want to include NUnit.<\/p>\n<p><a href=\"\/Users\/chass\/AppData\/Local\/Temp\/WindowsLiveWriter1560487288\/supfiles16D89AF\/image14.png\"><img decoding=\"async\" title=\"image_thumb6\" 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_thumb6\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/11\/2262.image_thumb6_533AE556.png\" width=\"183\" height=\"244\" \/><\/a><\/p>\n<p>Your project will then look like this, where (1) is included Dll and the NuGet package configuration file. (If you ever want to remove it, these two files are the ones to remove. If you got more packages, you must open and edit the packages.config.)<\/p>\n<p><a href=\"\/Users\/chass\/AppData\/Local\/Temp\/WindowsLiveWriter1560487288\/supfiles16D89AF\/SNAGHTML1b4cca11_thumb12.png\"><img decoding=\"async\" title=\"SNAGHTML1b4cca11_thumb1_thumb\" 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=\"SNAGHTML1b4cca11_thumb1_thumb\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/11\/7065.SNAGHTML1b4cca11_thumb1_thumb_1304CBDC.png\" width=\"244\" height=\"124\" \/><\/a><\/p>\n<p>Now you can add a new NUnit test file to your project, 2) in the screenshot above.<\/p>\n<p>NUnit has a different way of setting up categories, in fact it can be done in two different ways. You can add the category as a text string, the same way as you do it in MSTest above, or you can derive a new class from the Unit CategoryAttribute class. We have done both things below:<\/p>\n<p><a href=\"\/Users\/chass\/AppData\/Local\/Temp\/WindowsLiveWriter1560487288\/supfiles16D89AF\/image_thumb72.png\"><img decoding=\"async\" title=\"image_thumb7_thumb\" 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_thumb7_thumb\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/11\/8228.image_thumb7_thumb_00BC051A.png\" width=\"223\" height=\"244\" \/><\/a><\/p>\n<p>When opening up the Test Explorer now we see the following:<\/p>\n<p><a href=\"\/Users\/chass\/AppData\/Local\/Temp\/WindowsLiveWriter1560487288\/supfiles16D89AF\/image_thumb92.png\"><img decoding=\"async\" title=\"image_thumb9_thumb\" 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_thumb9_thumb\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/11\/0537.image_thumb9_thumb_675401DF.png\" width=\"204\" height=\"244\" \/><\/a><\/p>\n<p>Both methods are in the same Trait, named Category [CI], even if they were defined differently. That is pretty cool !<\/p>\n<p>Notice that the MSTest test that is in the CI category is placed in its own group.\u00a0 The categories from NUnit and MSTest are different even if they are spelled equally.\u00a0 That, however, only applies for categories.<\/p>\n<p>If we add in another test method and decorate that with the same kind of attributes that we did in the MSTest example in Part 1:<\/p>\n<p><a href=\"\/Users\/chass\/AppData\/Local\/Temp\/WindowsLiveWriter1560487288\/supfiles16D89AF\/image18.png\"><img decoding=\"async\" title=\"image_thumb8\" 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_thumb8\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/11\/3264.image_thumb8_271DE865.png\" width=\"244\" height=\"104\" \/><\/a><\/p>\n<p>In NUnit there are no explicit Owner and Priority property, but you can use the general Property attribute instead.\u00a0 The NUnit Property is more advanced than the MSTest Property, it has overloads for string, int and double, so implementing Priority with this makes it equal to the MSTest specific Priority.<\/p>\n<p>The output from this then becomes:<\/p>\n<p><a href=\"\/Users\/chass\/AppData\/Local\/Temp\/WindowsLiveWriter1560487288\/supfiles16D89AF\/image23.png\"><img decoding=\"async\" title=\"image_thumb11\" 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_thumb11\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/11\/5315.image_thumb11_38FA7C32.png\" width=\"153\" height=\"244\" \/><\/a><\/p>\n<p>Note that except for the categories, all the other properties are collected together for both MSTest and NUnit.<\/p>\n<p><strong>Status<\/strong><\/p>\n<ol>\n<li>Current version of the adapter at time of writing is 0.93.\u00a0 There is a <a href=\"https:\/\/bugs.launchpad.net\/nunit-vs-adapter\/+bug\/1075893\" target=\"_blank\" rel=\"noopener\"><u>bug concerning interoperability with Native C++<\/u><\/a> which is fixed in the upcoming 0.94 version, ETA Nov 30th 2012. <\/li>\n<li>Version 0.94 will also add class based Categories, see discussion below under xUnit.\u00a0 <\/li>\n<\/ol>\n<p>\u00a0<\/p>\n<p><strong><font size=\"3\">Adding in <a href=\"https:\/\/xunit.net\/\" target=\"_blank\" rel=\"noopener\"><u>xUnit.net<\/u><\/a><\/font><\/strong><\/p>\n<p>The <a href=\"http:\/\/visualstudiogallery.msdn.microsoft.com\/463c5987-f82b-46c8-a97e-b1cde42b9099\" target=\"_blank\" rel=\"noopener\"><u>xUnit.Net adapter<\/u><\/a> can also be found at Visual Studio Gallery (traits implemented in version 0.9.3), and the framework is found on NuGet the same way, search for \u201cxUnit\u201d, and install both the same way as done for NUnit, adding the libraries to the test project.\u00a0<\/p>\n<p><a href=\"\/Users\/chass\/AppData\/Local\/Temp\/WindowsLiveWriter1560487288\/supfiles16D89AF\/image181.png\"><img decoding=\"async\" title=\"image_thumb91\" 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_thumb91\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/11\/3755.image_thumb91_26B1B570.png\" width=\"244\" height=\"95\" \/><\/a><\/p>\n<p>In the xUnit.net framework, the different traits are implemented by decorating the test method with the Trait attribute.\u00a0 This is used for all kind of properties.\u00a0 Everything is a Trait in xUnit.\u00a0 It doesn\u2019t have any int overloads, so the priority must use a string representation, but the Test Explorer will treat that string and the MSTest int as the same.<\/p>\n<p>The same code then becomes:<\/p>\n<p><a href=\"\/Users\/chass\/AppData\/Local\/Temp\/WindowsLiveWriter1560487288\/supfiles16D89AF\/image61.png\"><img decoding=\"async\" title=\"image_thumb3\" 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_thumb3\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/11\/0216.image_thumb3_0D49B236.png\" width=\"225\" height=\"244\" \/><\/a><\/p>\n<p>You can also derive new classes from the TraitAttribute class, so if you like you can implement for example the Category, specific categories you want, and the Priority attributes that way:<\/p>\n<p><a href=\"\/Users\/chass\/AppData\/Local\/Temp\/WindowsLiveWriter1560487288\/supfiles16D89AF\/image25.png\"><img decoding=\"async\" title=\"image_thumb12\" 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_thumb12\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/11\/4010.image_thumb12_4D1398BB.png\" width=\"244\" height=\"181\" \/><\/a><\/p>\n<p>The results with both NUnit, MSTest and XUnit running at the same time is then:<\/p>\n<p><a href=\"\/Users\/chass\/AppData\/Local\/Temp\/WindowsLiveWriter1560487288\/supfiles16D89AF\/image33.png\"><img decoding=\"async\" title=\"image_thumb18\" 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_thumb18\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/11\/8032.image_thumb18_5EF02C88.png\" width=\"119\" height=\"244\" \/><\/a><\/p>\n<p>Both the NUnit and XUnit categores fall sweetly into the Categories group, MSTest are in its own special category types (CI, Developer and Production).\u00a0 They all treat the other traits equally. Notice that the special new attributes made above for \u2018CI\u2019 and \u2018Priority\u2019 are treated the same as the original ones.<\/p>\n<p><strong>Class based attributes<\/strong><\/p>\n<p>When I write unit tests I often group them by class.\u00a0 I rarely put two different types of unit tests in the same class.\u00a0 So, what I would like is to be able to decorate the class with Traits too.\u00a0 Those traits should then be treated as applying to all the methods in that class.\u00a0 It turns out that XUnit is the only framework I have tested so far that have this capability.\u00a0 MSTest refuses you to add the Traits to the class, they are bound to methods only.\u00a0 NUnit allows you to do it, but these traits have no effect yet, but the next version of the NUnit adapter should have this capability too for categories.<\/p>\n<p>We add some new test classes to all the projects, looking like this:<\/p>\n<p><a href=\"\/Users\/chass\/AppData\/Local\/Temp\/WindowsLiveWriter1560487288\/supfiles16D89AF\/image37.png\"><img decoding=\"async\" title=\"image_thumb20\" 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_thumb20\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/11\/5383.image_thumb20_4CA765C6.png\" width=\"244\" height=\"164\" \/><\/a><\/p>\n<p>(Equally for NUnit and MSTest, except different suffices, N11\/N12 and Ms11\/Ms12.<\/p>\n<p>And the results show that the NUnit and MSTest ends up the No Traits group, whereas the XUnit comes in correctly<\/p>\n<p><a href=\"\/Users\/chass\/AppData\/Local\/Temp\/WindowsLiveWriter1560487288\/supfiles16D89AF\/image42.png\"><img decoding=\"async\" title=\"image_thumb23\" 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_thumb23\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/11\/4810.image_thumb23_5E83F993.png\" width=\"134\" height=\"244\" \/><\/a><\/p>\n<p>\u00a0<\/p>\n<p><font size=\"3\"><strong>Adding in <a href=\"https:\/\/www.codeproject.com\/Articles\/6060\/MbUnit-Generative-Unit-Test-Framework\" target=\"_blank\" rel=\"noopener\"><u>MbUnit<\/u><\/a><\/strong><\/font><\/p>\n<p>To add in MbUnit one need to add first the <a href=\"http:\/\/gallio.org\/Downloads.aspx\" target=\"_blank\" rel=\"noopener\"><u>Gallio framework<\/u><\/a>, then the <a href=\"https:\/\/aka.ms\/mbunit-vs11\" target=\"_blank\" rel=\"noopener\"><u>MbUnit adapter<\/u><\/a>, and finally using NuGet to get the Gallio &amp; MbUnit dll\u2019s into your project:<\/p>\n<p><a href=\"\/Users\/chass\/AppData\/Local\/Temp\/WindowsLiveWriter1560487288\/supfiles16D89AF\/image47.png\"><img decoding=\"async\" title=\"image_thumb26\" 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_thumb26\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/11\/5808.image_thumb26_4C3B32D1.png\" width=\"244\" height=\"86\" \/><\/a><\/p>\n<p>\u00a0<\/p>\n<p>MbUnit has specific Traits, which matches some of the others, but not all.\u00a0 It has Category, Author and Importance.<\/p>\n<p><a href=\"\/Users\/chass\/AppData\/Local\/Temp\/WindowsLiveWriter1560487288\/supfiles16D89AF\/image76.png\"><img decoding=\"async\" title=\"image_thumb41\" 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_thumb41\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/11\/5074.image_thumb41_5E17C69E.png\" width=\"244\" height=\"243\" \/><\/a><\/p>\n<p>MBUnit also allows for derivation of new attribute classes like NUnit and xUnit.net, but the adapter doesn\u2019t support this for traits.<\/p>\n<p>One important thing to notice is that the adapter don\u2019t accept the Importance attribute shown above.\u00a0<\/p>\n<p>The current version of Gallio\/MbUnit, version 3.4 does not work correctly with its own version 3.4 of VS Test Adapter, giving an exception when you try to run it. The adapter seems to have been built for an earlier version.<\/p>\n<p>I did download their adapter code and made a few corrections and added the Trait code, just to see how the underlying MbUnit\/Gallio treats this.\u00a0 The adapter is only a bridge between the test runner and the test framework.\u00a0 I will try to get these code changes back up to the MbUnit project, so it should be ready to go in the next release.<\/p>\n<p><a href=\"\/Users\/chass\/AppData\/Local\/Temp\/WindowsLiveWriter1560487288\/supfiles16D89AF\/image72.png\"><img decoding=\"async\" title=\"image_thumb39\" 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_thumb39\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/11\/6153.image_thumb39_1DE1AD24.png\" width=\"195\" height=\"244\" \/><\/a><\/p>\n<p>Notice that we now are running 3 adapters at the same time &#8211; cool !<\/p>\n<p><strong>Status<\/strong><\/p>\n<p>Current version of the adapter (3.3) does not support Traits, but next version of the adapter will do so.<\/p>\n<p>\u00a0<\/p>\n<p><font size=\"3\"><strong>Adding in C++<\/strong><\/font><\/p>\n<p><strong><font size=\"2\">Managed C++<\/font><\/strong><\/p>\n<p>Test for Managed C++ is built-in in Visual Studio.\u00a0 It uses the same Traits as for C#. No surprises here.\u00a0<\/p>\n<p><a href=\"\/Users\/chass\/AppData\/Local\/Temp\/WindowsLiveWriter1560487288\/supfiles16D89AF\/image55.png\"><img decoding=\"async\" title=\"image_thumb30\" 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_thumb30\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/11\/3733.image_thumb30_5DAB93A9.png\" width=\"244\" height=\"123\" \/><\/a><\/p>\n<p>\u00a0<\/p>\n<p><strong><font size=\"2\">Native C++<\/font><\/strong><\/p>\n<p><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/hh598953(v=vs.110).aspx\" target=\"_blank\" rel=\"noopener\"><u>Test for Native C++<\/u><\/a> is also built-in to Visual Studio 2012.\u00a0 The set of traits available are different from managed, and the way they are set is different from managed C++. You can extend the traits by using the same property\/value mechanism, the attribute to use then is the TEST_METHOD_ATTRIBUTE which takes a property and a value as parameters.<\/p>\n<p><a href=\"\/Users\/chass\/AppData\/Local\/Temp\/WindowsLiveWriter1560487288\/supfiles16D89AF\/image4.png\"><img decoding=\"async\" title=\"image_thumb1\" 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_thumb1\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/11\/7446.image_thumb1_1D757A2F.png\" width=\"244\" height=\"155\" \/><\/a><\/p>\n<p>The attributes that matches the traits are the three shown in the code example above.<\/p>\n<p>The result when running this is then :<\/p>\n<p><a href=\"\/Users\/chass\/AppData\/Local\/Temp\/WindowsLiveWriter1560487288\/supfiles16D89AF\/image12%5B1%5D.png\"><img decoding=\"async\" title=\"image_thumb7[1]\" 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_thumb7[1]\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/11\/6064.image_thumb71_7230E327.png\" width=\"130\" height=\"244\" \/><\/a><\/p>\n<p>\u00a0<\/p>\n<p>C++ also has full support for class based and even module based traits.\u00a0 The example code below show a class based trait attribute<\/p>\n<p><a href=\"\/Users\/chass\/AppData\/Local\/Temp\/WindowsLiveWriter1560487288\/supfiles16D89AF\/image19%5B1%5D.png\"><img decoding=\"async\" title=\"image_thumb10\" 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_thumb10\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/11\/6076.image_thumb10_1D09473A.png\" width=\"244\" height=\"157\" \/><\/a><\/p>\n<p>and the result is then that this applies to all methods in this class.<\/p>\n<p><a href=\"\/Users\/chass\/AppData\/Local\/Temp\/WindowsLiveWriter1560487288\/supfiles16D89AF\/image20.png\"><img decoding=\"async\" title=\"image_thumb11[1]\" 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_thumb11[1]\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/11\/8623.image_thumb111_15EA0AC2.png\" width=\"244\" height=\"131\" \/><\/a><\/p>\n<p>So the C++ Unit Test framework supports all the traits and on all levels.\u00a0 That\u2019s very cool !<\/p>\n<p>\u00a0<\/p>\n<p>\u00a0<\/p>\n<p><font size=\"3\"><strong>Adding in JavaScript testing with <a href=\"http:\/\/chutzpah.codeplex.com\/\" target=\"_blank\" rel=\"noopener\"><u>Chutzpah<\/u><\/a><\/strong><\/font><\/p>\n<p>Chutzpah is the <a href=\"http:\/\/visualstudiogallery.msdn.microsoft.com\/f8741f04-bae4-4900-81c7-7c9bfb9ed1fe\" target=\"_blank\" rel=\"noopener\"><u>test adapter<\/u><\/a> for the <a href=\"http:\/\/qunitjs.com\/\" target=\"_blank\" rel=\"noopener\"><u>QUnit<\/u><\/a> and <a href=\"http:\/\/pivotal.github.com\/jasmine\/\" target=\"_blank\" rel=\"noopener\"><u>Jasmine<\/u><\/a> test frameworks for JavaScript.<\/p>\n<p>QUnit and Jasmine have the keywords \u2019Module\u2019 and \u2018Group\u2019 respectively that can be used to decorate the test methods.\u00a0 Those are the only ones available who can be used to implement Traits.\u00a0 They are semantically not meant like Traits, but can be used that way.<\/p>\n<p>Also note that Chutzpah currently runs tests per test file, not per test.\u00a0 So if you select a single test and runs that, all the other tests in the same file are also being executed. This imply you should consider how your Modules and tests are organized by file.\u00a0 One file should not contain more than one Module, if you intend to run them separately.\u00a0<\/p>\n<p>Again, I added a few lines trait coding to the Chutzpah source code, and this is how it looks, using Module as the keyword for a Trait.<\/p>\n<p><a href=\"\/Users\/chass\/AppData\/Local\/Temp\/WindowsLiveWriter1560487288\/supfiles16D89AF\/image80.png\"><img decoding=\"async\" title=\"image_thumb43\" 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_thumb43\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/11\/8688.image_thumb43_3CB82102.png\" width=\"244\" height=\"130\" \/><\/a><\/p>\n<p>And the results, together with the other tests.\u00a0 In the screenshot below, I have chosen to execute the first test in group a, and as can be seen the other tests are also run.<\/p>\n<p><a href=\"\/Users\/chass\/AppData\/Local\/Temp\/WindowsLiveWriter1560487288\/supfiles16D89AF\/clip_image0014.png\"><img decoding=\"async\" title=\"clip_image001_thumb1\" 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=\"clip_image001_thumb1\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/11\/4401.clip_image001_thumb1_7C820787.png\" width=\"108\" height=\"244\" \/><\/a><\/p>\n<p>\u00a0<\/p>\n<p><strong>Status<\/strong><\/p>\n<ol>\n<li>The current version at time of writing (Nov. 12th 2012) of Chutzpah is 2.2.1. This version does not support Traits.\u00a0 The next version will support traits. <\/li>\n<\/ol>\n<p>\u00a0<\/p>\n<p><font size=\"3\"><strong>Summary<\/strong><\/font><\/p>\n<p>\u00a0<\/p>\n<p><strong>Release schedules for trait aware 3rd party framework adapters<\/strong><\/p>\n<table cellspacing=\"0\" cellpadding=\"2\" width=\"400\" border=\"0\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"133\">\n        <strong>Framework<\/strong>\n      <\/td>\n<td valign=\"top\" width=\"133\">\n        <strong>ETA<\/strong>\n      <\/td>\n<td valign=\"top\" width=\"133\">\n        <strong>Comment<\/strong>\n      <\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"133\">\n        NUnit\n      <\/td>\n<td valign=\"top\" width=\"133\">\n        Nov. 30th 2012, version 0.94\n      <\/td>\n<td valign=\"top\" width=\"133\">\n        \u00a0\n      <\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"133\">\n        xUnit.Net\n      <\/td>\n<td valign=\"top\" width=\"133\">\n        Current version 0.9.3\n      <\/td>\n<td valign=\"top\" width=\"133\">\n        \u00a0\n      <\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"133\">\n        MbUnit\n      <\/td>\n<td valign=\"top\" width=\"133\">\n        Next version, date TBD\n      <\/td>\n<td valign=\"top\" width=\"133\">\n        Code ready\n      <\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"133\">\n        Chutzpah\n      <\/td>\n<td valign=\"top\" width=\"133\">\n        Next version, date TBD\n      <\/td>\n<td valign=\"top\" width=\"133\">\n        Solution ready, needs coding and some time\n      <\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u00a0<\/p>\n<p><strong>Traits summarized<\/strong><\/p>\n<p>The first column merely sets a generic name for the traits, to be able to compare them between the adapters\/frameworks. The \u2018&#8212;-\u2018 means \u201cNot implemented\u201d.<\/p>\n<table cellspacing=\"0\" cellpadding=\"2\" width=\"694\" border=\"0\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"72\">\n        <strong>Trait \u2018generic\u2019 name<\/strong>\n      <\/td>\n<td valign=\"top\" width=\"96\">\n        <strong>MSTest (C# and Man C++)<\/strong>\n      <\/td>\n<td valign=\"top\" width=\"66\">\n        <strong>Native C++<\/strong>\n      <\/td>\n<td valign=\"top\" width=\"81\">\n        <strong>NUnit<\/strong>\n      <\/td>\n<td valign=\"top\" width=\"92\">\n        <strong>xUnit.Net<\/strong>\n      <\/td>\n<td valign=\"top\" width=\"139\">\n        <strong>MbUnit<\/strong>\n      <\/td>\n<td valign=\"top\" width=\"146\">\n        <strong>Chutzpah<\/strong>\n      <\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"72\">\n        Category\n      <\/td>\n<td valign=\"top\" width=\"96\">\n        Category\n      <\/td>\n<td valign=\"top\" width=\"66\">\n        TEST_METHOD_ATTRIBUTE(\u201cCategory\u201d,<value>) <\/value>\n      <\/td>\n<td valign=\"top\" width=\"81\">\n        Category\n      <\/td>\n<td valign=\"top\" width=\"92\">\n        Trait(\u201cCategory\u201d,<value>) <\/value>\n      <\/td>\n<td valign=\"top\" width=\"139\">\n        Category\n      <\/td>\n<td valign=\"top\" width=\"146\">\n        Module\n      <\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"72\">\n        Priority\n      <\/td>\n<td valign=\"top\" width=\"96\">\n        Priority\n      <\/td>\n<td valign=\"top\" width=\"66\">\n        TEST_PRIORITY\n      <\/td>\n<td valign=\"top\" width=\"81\">\n        Property(\u201cPriority\u201d,<value>) <\/value>\n      <\/td>\n<td valign=\"top\" width=\"92\">\n        Trait(\u201cPriority\u201d,<value>) <\/value>\n      <\/td>\n<td valign=\"top\" width=\"139\">\n        &#8212;- (<strike>Importance<\/strike>)\n      <\/td>\n<td valign=\"top\" width=\"146\">\n        &#8212;-\n      <\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"72\">\n        Owner\n      <\/td>\n<td valign=\"top\" width=\"96\">\n        Owner\n      <\/td>\n<td valign=\"top\" width=\"66\">\n        TEST_OWNER\n      <\/td>\n<td valign=\"top\" width=\"81\">\n        Property(\u201cOwner\u201d,<value>) <\/value>\n      <\/td>\n<td valign=\"top\" width=\"92\">\n        Trait(\u201cCategory\u201d,<value>) <\/value>\n      <\/td>\n<td valign=\"top\" width=\"139\">\n        Author(kind of)\n      <\/td>\n<td valign=\"top\" width=\"146\">\n        &#8212;-\n      <\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"72\">\n        Property\n      <\/td>\n<td valign=\"top\" width=\"96\">\n        Property\n      <\/td>\n<td valign=\"top\" width=\"66\">\n        TEST_METHOD_ATTRIBUTE\n      <\/td>\n<td valign=\"top\" width=\"81\">\n        Property\n      <\/td>\n<td valign=\"top\" width=\"92\">\n        Trait\n      <\/td>\n<td valign=\"top\" width=\"139\">\n        &#8212;-\n      <\/td>\n<td valign=\"top\" width=\"146\">\n        &#8212;-\n      <\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"72\">\n        \u00a0\n      <\/td>\n<td valign=\"top\" width=\"96\">\n        \u00a0\n      <\/td>\n<td valign=\"top\" width=\"66\">\n        \u00a0\n      <\/td>\n<td valign=\"top\" width=\"81\">\n        \u00a0\n      <\/td>\n<td valign=\"top\" width=\"92\">\n        \u00a0\n      <\/td>\n<td valign=\"top\" width=\"139\">\n        \u00a0\n      <\/td>\n<td valign=\"top\" width=\"146\">\n        \u00a0\n      <\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"72\">\n        Support inheritance\n      <\/td>\n<td valign=\"top\" width=\"96\">\n        No\n      <\/td>\n<td valign=\"top\" width=\"66\">\n        No\n      <\/td>\n<td valign=\"top\" width=\"81\">\n        Yes\n      <\/td>\n<td valign=\"top\" width=\"92\">\n        Yes\n      <\/td>\n<td valign=\"top\" width=\"139\">\n        No\n      <\/td>\n<td valign=\"top\" width=\"146\">\n        NA\n      <\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"72\">\n        Class based traits\n      <\/td>\n<td valign=\"top\" width=\"96\">\n        No\n      <\/td>\n<td valign=\"top\" width=\"66\">\n        Yes\n      <\/td>\n<td valign=\"top\" width=\"81\">\n        Yes\n      <\/td>\n<td valign=\"top\" width=\"92\">\n        Yes\n      <\/td>\n<td valign=\"top\" width=\"139\">\n        No\n      <\/td>\n<td valign=\"top\" width=\"146\">\n        NA\n      <\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Property is a generic property\/value set, and support for that is very nice to have. Implementing that means the traits are very extensible, and you can twist them to anything you like, and have full support of that in the Test Explorer.<\/p>\n<p>Have fun !<\/p>\n<p>\u00a0<\/p>\n<blockquote>\n<hr \/>\n<\/blockquote>\n<p>&#42;*****************************<\/p>\n<p>\u00a0<\/p>\n<p>By<\/p>\n<h6><a href=\"http:\/\/geekswithblogs.net\/terje\/Default.aspx\"><font size=\"3\">Terje Sandstrom<\/font><\/a><\/h6>\n<p>&#8212;&#8212; Chief Software Geek at Inmeta Consulting in Scandinavia &#8212;&#8211; and a Visual Studio ALM MVP<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2012\/11\/terjes_1336086861_84.png\" width=\"131\" height=\"120\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As promised one of the ALM MVPs, Terje Sandstrom, has delivered Part 2 of his Unit Test Series: \u201cUsing Traits with different test frameworks in the Unit Test Explorer\u201d. From the traffic and comments on his first post these are clearly very appreciated articles! Thanks Terje! \u00a0 *********************************************************************************************************************************************\u2019 In Part 1\u00a0 traits in general was [&hellip;]<\/p>\n","protected":false},"author":77,"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-3903","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops"],"acf":[],"blog_post_summary":"<p>As promised one of the ALM MVPs, Terje Sandstrom, has delivered Part 2 of his Unit Test Series: \u201cUsing Traits with different test frameworks in the Unit Test Explorer\u201d. From the traffic and comments on his first post these are clearly very appreciated articles! Thanks Terje! \u00a0 *********************************************************************************************************************************************\u2019 In Part 1\u00a0 traits in general was [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/3903","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\/77"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/comments?post=3903"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/3903\/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=3903"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/categories?post=3903"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/tags?post=3903"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}