【问题标题】:nunit-console can not loacte fixturenunit-console 找不到夹具
【发布时间】:2011-05-30 10:14:26
【问题描述】:

我有 2.5.8 和 VS2010

我想针对一个 dll 运行测试,如果我输入了

nunit-console a.dll

我也有这些套房

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

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

如果我想使用 Suites 运行测试,请输入

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

但它失败并显示消息

无法找到夹具 AllTests.Suite

如果你想知道我为什么使用 Suites,我不知道。我们在我们的项目中使用 MSBuild,我猜这是 MSBuild 的要求。

任何帮助表示赞赏。问候。

【问题讨论】:

    标签: c# unit-testing msbuild nunit


    【解决方案1】:

    在你的类前面加上以下标签 [测试夹具]

    我认为这是缺少的,

    虽然我没有使用过套件。但是我的正常单元测试类似于这样

    [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()>);
    }
    
    } 
    

    并以 nunit-console nunit.tests.dll [无论生成的 dll 是什么] 运行测试

    告诉我这是否有帮助

    【讨论】:

    • 嗨。其实我没有问这个。这就是我们调用和运行测试的方式。我的问题是关于使用套件。 AFAIK 套件用于对测试进行分组。它们现在使用不多,而是使用类别。
    • 啊抱歉!没有太多的套房经验
    【解决方案2】:

    我找到了解决办法。

    诀窍是命名空间。 alltests 和 unittests 类的命名空间应该是

    "Suites".
    

    否则我会一直收到“无法定位”。 问候

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-20
      • 2021-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多