【问题标题】:Grouping Methods in Test Structure of Nunit GuiNunit Gui 测试结构中的分组方法
【发布时间】:2011-01-26 12:35:56
【问题描述】:

目前我有 nunit 的 gui 测试结构设置来使用自动命名空间套件。

我想知道是否可以在 TestFixture 中对方法名称进行分组。

此刻,这棵树看起来像

MyClassTest
 +Method-1 test1
 +Method-1 test2
 +Method-1 test3
 +Method-2 test1...

我想知道是否有可能让树看起来像

MyClassTest
 +Method1
   ++Method-1 Test1
   ++Method-1 Test2
   ++Method-1 Test3
 +Method2
   ++Method-2 Test1

我为什么要这样做?这是因为我只想选择“Method-1”节点并让它运行该方法的所有测试。我只是省去了检查该方法的所有测试的问题。

背景:使用 vb.net 和 vs2010 pro。

编辑:如果我在“Myclass”中创建一个名为“Method1”的类,我会得到以下内容

MyClassTest
 +Method-2 test1
MyCalssTest+Method-1
   +Test1
   +Test2

【问题讨论】:

    标签: .net vb.net unit-testing nunit


    【解决方案1】:

    我通过创建一个Method1 测试夹具类并将 Method1Test1、Method1Test2 等测试函数作为该类的成员来做到这一点。例如。 (在 C# 中)

    [TestFixture]
    public class Method1
    {
        [Test]
        public void Method1Test1()
        {
           ... 
        }
    
        [Test]
        public void Method1Test2()
        {
           ... 
        }
    } 
    

    【讨论】:

    • 我在“Myclass”中创建了一个名为 Method1 的新类,但不是作为树中“Myclass”节点的子节点;它成为名为 MyBranch+Method1 的姊妹分支。
    • 将 Myclass 设为命名空间,并将所有 Method1、Method2 等类放入其中 - 你会得到你想要的。
    • 完美。感谢您的提示!
    • 另一方面,我可以摆脱用于对方法进行分组的糟糕区域!
    【解决方案2】:

    NUnit 的 Category 属性也可能有帮助。

    【讨论】:

    • 好建议,以后我会考虑用于其他用途。
    猜你喜欢
    • 2015-06-03
    • 2012-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多