Visual Studio 2012 Test Category Categories Hierarchy (Test Explorer)

I am testing a rather large project (C #, VS2012), and I need to organize my unit test in a test hierarchy (for example: now I have 43 test cases). I really need a hierarchy.

I have already defined categories of tests, and the test guide shows test cases by signs. I have categories this way (one test has several categories)

  • TestCase01: MainTestType, SubTestType, SubsubTestType
  • ...
  • TestCase10: MainTestType, SubTestType, SubsubTestType
  • TestCase11: MainTestType, SubTestType2, SubsubTestType2
  • ...
  • TestCase15: MainTestType, SubTestType2, SubsubTestType2

It is defined as follows:

[TestMethod] [TestCategory("MainTestType")] [TestCategory("SubTestType")] [TestCategory("SubsubTestType")] public void MyTestCase() { /* etc. */ 

But Test Explorer shows the following:

  • MainTestType: all tests that have the MainTestType category
  • SubTestType: all tests that have the SubTestType category
  • etc...

So, I really miss the hierarchy. I tried "Cat1 \ Cat2 \ Cat3" or even with /. But no hierarchy is displayed. Do you know how to do this, or a free addon that can do this for me?

I will also need this type of categorization, because we often run tests from the command line, and mstest.exe can run tests for one category (for example, all MainTestType or SubTestType). (I stick with mstest because half of the team uses vs2010). But the solution is enough for vs2012.

Thanks in advance.

+7
source share
4 answers

While I was searching, it is currently not supported, I made the following workaround:

  • create project
  • run MSText for all tests -> .trx output
  • a simple winforms / wpf program that parses .trx, gets test cases and displays them in a tree
  • now we can run mstest from this application for the selected node β†’ .trx file (which can be opened in VS)

I used .trx because I do not need to parse the assembly, mstest.exe does this. Test categories are created as follows:

 [TestCategory("MainTestType")] [TestCategory("MainTestType/SubTestType")] [TestCategory("MainTestType/SubTestType/SubsubTestType")] 

So, the workaround, which is simple, can only use one binary and the developers. The problem with the playlist was that they are also not hierarchical.

+6
source

Test Explorer shows only the groups following the TestFilter / InnerTests test.

The New Tester tab is a common container. Using the special / addon / plugin adapters, you can integrate other test environments (NUnit, xUnit, Qunit, ...) into the Test Explorer ... but these adapters must follow the interface of the test explorer.

Thus, it is not supported on the Test Explorer tab, I have not found a way to expand the test explorer tab before.

Perhaps another test structure will allow you to have a hierarchy, but it will be in a different custom tab and with a different attribute (TestCategory is an MSTest attribute).

Just for information, you can thus combine the features in the test explorer window.

 Trait:"MainTestType1" Trait:"SubTestType3" 
+1
source

To group in VS2010, use the .vsmdi files that can be opened in the Test List Editor .

Regarding VS2012:

Visual Studio 2012 Update 1 http://www.microsoft.com/visualstudio/eng/visual-studio-update added improvements to support grouping and filtering by Project and Traits (category). The use of these functions is described in detail in this blog post, 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

The group and filter by classes are complete and will be available in Update 2.

I suggest you move the categories to the namespace so that you can see the flat hierarchy in the TestView window in the FullClassName column.

+1
source

You can trick a little by making your level 2 trait a concatenation of the values ​​of your first two levels. So, if level 1 is Animal and level 2 is Mammal, you can have Trapt "Animal.Mammal". In Test Explorer, you get a node for Level1 [Animal] , another for Level1 [Plant] , and then one for Level2 [Animal.Tiger] . I believe the filter supports substring matches, so there’s one way to sort it. You still don't get the tree structure (although if you were connected and decided, you can try the extended characters of the ascii art channel, such as the old DOS tree command).

You also have a problem that you cannot combine different traits (so that all the birds are together on the list all the way down).

On the other hand, the forced use of the hierarchy structure when resolving n-tuples of attributes will be inconvenient. He would have to limit the elements from more than one path from the top of the hierarchy, define and report loops, use the tree control on top (or with the matrix), which is now there. Also, when you use refactoring code and want tests to be organized in parallel, an existing structure that is too large can cause headaches.

0
source

All Articles