vendredi 4 mars 2016

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:

Test list

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;
        }
    }

Aucun commentaire:

Enregistrer un commentaire