Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2012 test categories hierarchy (Test Explorer)

I am testing a quite big project (C#, VS2012), and I need to arrange my unit test in test hierarchy (eg.: now I have 43 test cases). I do really need the hierarchy.

I have test categories defined already, and the test explorer shows test cases by traits. I have categories in this way (one test have several categories)

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

Defined like this:

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

But Test Explorer shows the next:

  • MainTestType: all tests having category MainTestType
  • SubTestType: all tests having category SubTestType
  • etc...

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

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

Thank you in advance.

like image 544
lajos.cseppento Avatar asked May 11 '13 10:05

lajos.cseppento


People also ask

How do I use test Explorer code in Visual Studio?

Tests can be run from Test Explorer by right-clicking in the code editor on a test and selecting Run test or by using the default Test Explorer shortcuts in Visual Studio. Some of the shortcuts are context-based. This means that they run or debug tests based on where your cursor is in the code editor.

What is test category?

Test category means one type of test or group of tests specified by rule under sub. (4) for similar materials or classes of materials or which utilize similar methods or related methods.

How do I debug a test in Visual Studio?

To start debugging: In the Visual Studio editor, set a breakpoint in one or more test methods that you want to debug. Because test methods can run in any order, set breakpoints in all the test methods that you want to debug. In Test Explorer, select the test method(s) and then choose Debug on the right-click menu.

Can we test private methods in unit testing?

Why We Shouldn't Test Private Methods. As a rule, the unit tests we write should only check our public methods contracts. Private methods are implementation details that the callers of our public methods aren't aware of. Furthermore, changing our implementation details shouldn't lead us to change our tests.


1 Answers

As what I searched for is not supported at the moment, I made the next workaround:

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

I used .trx because that way I don't have to do parse the assembly, mstest.exe does it. Test categories are made this way:

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

So the is the workaround which is simple, only one binary and the developers can use too. The problem with playlist was that they aren't hierarchical neither.

like image 164
lajos.cseppento Avatar answered Nov 14 '22 22:11

lajos.cseppento