简体   繁体   English

使用Nunit测试适配器在Visual Studio 2013中按类名称和方法名称进行分组测试

[英]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: 我在Visual Studio Test Explorer中遇到这个问题:找不到我需要运行的选择测试的方法:

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. 我用TestCaseSource作为输入数据进行了很多测试,测试浏览器在许多测试中转换了这些数据,因此对于我一种测试方法,我可以输入20-30个条目。 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. 我知道我可以使用Traits但它们不呈现为层次结构,也不嵌套在类分组下。

Now i have only 2 methods in one class and this is the result: 现在我在一个类中只有2个方法,这是结果:

测试清单

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 在一个方法中选择所有案例都是很痛苦的,当我什至可以使用20种方法时,最终无法想象情况

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. 这是Visual Studio Test Explorer(不是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. NUnit适配器仅将信息提供给测试窗口,它不控制任何UI,因此NUnit团队无法改善其工作方式。

I would suggest heading over to the Visual Studio UserVoice and voting on or entering an issue to give Test Explorer some love. 我建议前往Visual Studio UserVoice并投票或输入问题以给予Test Explorer一些支持。

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测试资源管理器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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