简体   繁体   中英

NUnit not running Suite tests

I've created a test suite in NUnit that references several distinct unit test fixtures in various assemblies.

I've pretty much used the example code from NUnit's docs :

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: 替代文字

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. 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.

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"?

[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 :)

Suites are currently not displayed in the Gui or run automatically by either runner when they are encountered. The historical purpose of the Suite mechanism was to provide a way of aggregating tests at the top level of each run. Hence, they are only supported when used with the /fixture option on the console or gui command line.

Update 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). This allows a fixed set of test assembly references to be configured and then loaded into the GUI or run by the console runner:

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. 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. You have to run them from the console, and only using the /fixture option. For example, to run the suite you specified above, you'd run (assuming your class was compiled into an assembly 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. You can however run them from the console that is built into the GUI using commands like the above.


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

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