nunit-console can not loacte fixture

牧云@^-^@ 提交于 2019-12-13 03:42:22

问题


I have 2.5.8 and VS2010

I want to run tests against a dll and if I type

nunit-console a.dll

I also have these suites

public class AllTests
{
    [Suite]
    public static IEnumerable Suite
    {
        get
        {
            List<Type> suite = new List<Type>();
            foreach (Type testCase in UnitTests.Suite)
            {
                suite.Add(testCase);
            }
            return suite;
        }
    }
}

and

public class UnitTests
{
    [Suite]
    public static IEnumerable Suite
    {
        get
        {
            List<Type> suite = new List<Type>();
            suite.Add(typeof(LicenceManagerTests));
            suite.Add(typeof(CertManagerTests));
            return suite;
        }
    }
}

If I would like to run tests using Suites I type

nunit-console a.dll /fixture=AllTests.Suite

but it fails with the message

Unable to locate fixture AllTests.Suite

If you wonder why I use Suites ,I don't know. We are using MSBuild in our project and this is a requirement of MSBuild I guess.

Any help appreciated. Regards.


回答1:


Precede your class with the following tag [TestFixture]

I think that is what is missing,

While I have not used suites. But my normal unit tests resemble something like this

[TestFixture]
public class A
{
//Properties
[Setup]
public void Setup()
{
//Setup code before each test, usually to set any constants, properties defined above
}
[Test]
public void TestA()
{
//test code
Asset.IsTrue(<func()>);
}

} 

and run the test as nunit-console nunit.tests.dll [whatever is the dll generated]

Tell me if that helps




回答2:


I found the solution.

The trick is namespace. Namespace of alltests and unittests classes should be

"Suites".

Otherwise I keep receving "unable to locate".. Regards



来源:https://stackoverflow.com/questions/4526678/nunit-console-can-not-loacte-fixture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!