c# - nunit-console 不会运行任何测试

标签 c# mono nunit

我正在通过 Mono 测试驱动 .Net 生态系统,但我遇到了 NUnit 的问题。我有以下示例测试文件:

using NUnit.Framework;

namespace Tests
{
    [TestFixture]
    class Tests
    {
        [Test]
        public void FailingTest()
        {
            Assert.Fail("A message");
        }

        [Test]
        public void PassingTest()
        {
        }
    }
}

我正在构建和运行的是:

cweber@mbp ~/temp/monoexample$ dmcs tests.cs -target:library -r:$NUNIT_FRAMEWORK_DLL
cweber@mbp ~/temp/monoexample$ ls tests.dll
tests.dll
cweber@mbp ~/temp/monoexample$ nunit-console tests.dll
NUnit version 2.4.8
Copyright (C) 2002-2007 Charlie Poole.
Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov.
Copyright (C) 2000-2002 Philip Craig.
All Rights Reserved.

Runtime Environment -
   OS Version: Unix 14.5.0.0
  CLR Version: 4.0.30319.17020 ( 4.2.1 (explicit/6dd2d0d Fri Nov  6 12:25:19 EST 2015) )

.N.N
Tests run: 0, Failures: 0, Not run: 2, Time: 0.014 seconds

如您所见,两个测试都没有运行。

我用谷歌搜索了所有我能想到的东西,并且我已经完成了所有我能想到的实验(例如,删除 namespace ,弄乱 fixturerun标志等)。我已经尽我所能清楚地简化了这个例子,但是我已经没有想法了。如果我可以提供更多信息,请告诉我!

如果答案很明显,我很抱歉问这个问题。

最佳答案

查看您的 TestResult.xml 文件,您会发现原因,类不是公开的 ;-)

    <results>
      <test-case name="Tests.Tests.FailingTest" executed="False">
        <reason>
          <message><![CDATA[Fixture class is not public]]></message>
        </reason>
      </test-case>
      <test-case name="Tests.Tests.PassingTest" executed="False">
        <reason>
          <message><![CDATA[Fixture class is not public]]></message>
        </reason>
      </test-case>
    </results>

关于c# - nunit-console 不会运行任何测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33849138/

相关文章:

C# - 如果拆分字符位于括号内,则忽略它

c# - 如何调用具有多个参数的测试方法(NUnit)

c# - 为单元测试哈希表数据类型生成随机值

c# - 如何在.net中的Web服务中调度[WebMethod]?

c# - WPF中的Count属性的INotifyPropertyChanged?

c# - 取一个ref参数的地址

android - 是否可以在 Mono Android 中使用不带 ListActivity 的 ListView?

c++ - 使 C++ 库可用于 .Net

c# - 在 Unity3d 中处理文件时使用 System.IO 是否安全?

java - 单元测试 : Is it bad practice to call public methods (for setup) while testing another method?