简体   繁体   English

NUnit没有运行套件测试

[英]NUnit not running Suite tests

I've created a test suite in NUnit that references several distinct unit test fixtures in various assemblies. 我在NUnit中创建了一个测试套件,它引用了各种组件中的几个不同的单元测试夹具。

I've pretty much used the example code from NUnit's docs : 我几乎使用了NUnit文档中的示例代码:

namespace NUnit.Tests
{
    using System;
    using NUnit.Framework;
    using System.Collections;

    public class AllTests
    {
        [Suite]
        public static IEnumerable Suite
        {
            get
            {
                ArrayList suite = new ArrayList();
                suite.Add(new VisionMap.DotNet.Tests.ManagedInteropTest.DotNetUtilsTest());
                return suite;
            }
        }
    }
}

My goal is to add several tests to the list above so I can run them all in a batch. 我的目标是在上面的列表中添加几个测试,以便我可以批量运行它们。

But when I try to load the DLL in NUnit's GUI I get this: 但是当我尝试在NUnit的GUI中加载DLL时,我得到了这个: 替代文字

What am I doing wrong? 我究竟做错了什么?

I'm aware that the docs say the GUI won't run suites, but I've tried the console as well. 我知道文档说GUI不会运行套件,但我也尝试过控制台。 Can somebody please tell me what Suites are good for and how I can use them to achieve my goal? 有人可以告诉我套房有什么用处以及如何使用它们来实现我的目标吗?

I'm using nunit 2.5.0.9122. 我正在使用nunit 2.5.0.9122。

Edit 编辑

Well, no answers are forthcoming. 好吧,没有答案即将到来。 I found an alternative solution in the end: Categories. 我最终找到了另一种解决方案:分类。 I group test fixtures by giving them appropriate categories and then I can run a subset of them in batch, while still ignoring another subset. 我通过给出适当的类别对测试夹具进行分组,然后我可以批量运行它们的子集,同时仍然忽略另一个子集。

Still, very odd that this Suite feature seems to be completely broken. 但是,很奇怪这个套件功能似乎完全被打破了。

Is there any reason why you are returning "IEnumerable" instead of "TestSuite"? 您有没有理由返回“IEnumerable”而不是“TestSuite”?

[Suite]
public static TestSuite Suite 

Update 更新

Reading the small-print at the bottom of the page at NUnit site, it looks like Suite type tests will not show in in the Gui runner, so I guess that's the issue :) 在NUnit网站上阅读页面底部的小字体,看起来套件类型测试不会显示在Gui跑步者中,所以我猜这就是问题:)

Suites are currently not displayed in the Gui or run automatically by either runner when they are encountered. 套件目前不会显示在Gui中,也不会遇到任何一个跑步者自动运行。 The historical purpose of the Suite mechanism was to provide a way of aggregating tests at the top level of each run. Suite机制的历史目的是提供一种在每次运行的顶层聚合测试的方法。 Hence, they are only supported when used with the /fixture option on the console or gui command line. 因此,只有在控制台或gui命令行上使用/ fixture选项时才支持它们。

Update 2 更新2

I'm not sure what you are trying to achieve with the "Suite" feature, but if you are trying to find a way of configuring a set of test assemblies to be run together, I have used " NUnit Test Projects " to do this in the past (it's just an xml config file listing test dlls). 我不确定你试图通过“套件”功能实现什么,但是如果你想找到一种配置一组测试组件来一起运行的方法,我已经使用“ NUnit测试项目 ”来做到这一点在过去(它只是一个列出测试dll的xml配置文件)。 This allows a fixed set of test assembly references to be configured and then loaded into the GUI or run by the console runner: 这允许配置一组固定的测试程序集引用,然后将其加载到GUI或由控制台运行程序运行:

http://www.nunit.org/index.php?p=multiAssembly&r=2.5.5 http://www.nunit.org/index.php?p=multiAssembly&r=2.5.5

Suites aren't really needed for anything much at all these days. 这些天来,套房并不是真正需要的。 If you only wanted to use them to specify which tests do and don't get run this is much better achieved with Category attributes. 如果您只想使用它们来指定哪些测试执行和不运行,则使用Category属性可以更好地实现。 This is what you ended up doing, and sounds like the best solution to your problem. 这就是你最终做的事情,听起来像是你问题的最佳解决方案。

However, for others' and future reference, you can still use Suites in Nunit. 然而,对于别人的和未来的参考,你仍然可以在NUnit的使用套房。 You have to run them from the console, and only using the /fixture option. 您必须从控制台运行它们,并且只使用/ fixture选项。 For example, to run the suite you specified above, you'd run (assuming your class was compiled into an assembly AllTests.dll): 例如,要运行上面指定的套件,您将运行(假设您的类已编译为程序集AllTests.dll):

nunit-console /fixture:AllTests.Suite AllTests.dll

You won't see any evidence of or way to run suites in the GUI - this is noted in the documentation. 您将看不到任何在GUI中运行套件的证据或方式 - 这在文档中有说明。 You can however run them from the console that is built into the GUI using commands like the above. 但是,您可以使用上述命令从GUI内置的控制台运行它们。


I use suites in some of my testing because I have some odd use cases that require me to sometimes need to pass an argument to my test methods. 我在一些测试中使用套件,因为我有一些奇怪的用例,需要我有时需要将参数传递给我的测试方法。 I do this by creating a suite such as the below. 我这样做是通过创建如下的套件来实现的。 So there are some uses for them, just none needed in your case. 所以它们有一些用途,在你的情况下根本不需要。

[Suite]
    public static IEnumerable MySuite
    {
        get
        {
            var suite = new ArrayList{new TestClass1(arg1), TestClass2(arg2)};
            return suite;
        }
    }

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

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