简体   繁体   中英

Group test by class name and method name in visual studio 2013 with Nunit test adapter

I have this problem with visual studio test explorer: can't find a way to select test i need to run:

i have many tests with TestCaseSource as input data that test explorer translate in many tests, so for i single test method i can have 20-30 entry. when i start to have many test in my class, select all entry of a single method is a pain

i know i can use Traits but they are not render as hierarchy nor nested under class grouping.

Now i have only 2 methods in one class and this is the result:

测试清单

where selecting all case for a single method is painful, cant image the situation at the end when i can even 20 methods like that

Is there any way for grouping tests by project, then by class and then by method without having to write a class for every tests?

for complete info this is my code

public class TestCase
    {
        public static IEnumerable TestCasesIsNumerico
        {
            get
            {
                yield return new TestCaseData("12").Returns(true);
                yield return new TestCaseData("12345678901234567890").Returns(true);
                yield return new TestCaseData("1,2").Returns(true);
                yield return new TestCaseData("1.2").Returns(true);             
                yield return new TestCaseData("1.000,12").Returns(true);
                yield return new TestCaseData("1,000.12").Returns(true);
                yield return new TestCaseData("1.000.000").Returns(true);
                yield return new TestCaseData("1,000,000").Returns(true);
                yield return new TestCaseData("1.000.000.000.000").Returns(true);
                yield return new TestCaseData("1,000,000,000,000").Returns(true);
                yield return new TestCaseData("1.000.000,00").Returns(true);
                yield return new TestCaseData("1,000,000.00").Returns(true);
                yield return new TestCaseData("a").Returns(false);
                yield return new TestCaseData("a120").Returns(false);
                yield return new TestCaseData("12a0").Returns(false);
                yield return new TestCaseData("120a").Returns(false);
                yield return new TestCaseData("01").Returns(false);
                yield return new TestCaseData("1.1.1").Returns(false);
                yield return new TestCaseData("1,1,1").Returns(false);
                yield return new TestCaseData("1.000.12").Returns(false);
                yield return new TestCaseData("1,000,12").Returns(false);
            }
        }

        public static IEnumerable TestCasesValoreNumero
        {
            get
            {
                yield return new TestCaseData("12").Returns(12);
                yield return new TestCaseData("12345678901234567890").Returns(12345678901234567890);
                yield return new TestCaseData("1,2").Returns(1.2);
                yield return new TestCaseData("1.2").Returns(1.2);
                yield return new TestCaseData("1.000,12").Returns(1000.12);
                yield return new TestCaseData("1,000.12").Returns(1000.12);
                yield return new TestCaseData("1.000.000").Returns(1000000);
                yield return new TestCaseData("1,000,000").Returns(1000000);
                yield return new TestCaseData("1.000.000.000.000").Returns(1000000000000);
                yield return new TestCaseData("1,000,000,000,000").Returns(1000000000000);
                yield return new TestCaseData("1.000.000,12").Returns(1000000.12);
                yield return new TestCaseData("1,000,000.12").Returns(1000000.12);
            }
        }
    }

    [TestFixture]
    public class UtilitaTests
    {
        [Test, TestCaseSource(typeof(TestCase), "TestCasesIsNumerico")]
        public bool isValoreNumerico_RitornaVeroSeNumero(object  o)
        {
            decimal d;
            return Utilita.tryValoreNumerico(o, out d);
        }


        [Category("UtilitaTests-isValoreNumerico_RitornaNumeroCorretto")]
        public decimal isValoreNumerico_RitornaNumeroCorretto(object o)
        {
            decimal d;
            Utilita.tryValoreNumerico(o, out d);
            return d;
        }
    }

Unfortunately, it isn't possible beyond grouping at a top level of traits (categories), test assemblies, classes, etc. which you have already found.

This is a limitation of the Visual Studio Test Explorer, not NUnit. The NUnit adapter only supplies the information to the test window, it does not control any of the UI, so the NUnit team cannot improve the way it works.

I would suggest heading over to the Visual Studio UserVoice and voting on or entering an issue to give Test Explorer some love.

You already know, but some people don't realize that you can change the grouping of tests in the Test Explorer Window. To do so, right click on any node in your tests and select group by.

Visual Studio测试资源管理器

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM