我正在通过 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 ,弄乱 fixture
和 run
标志等)。我已经尽我所能清楚地简化了这个例子,但是我已经没有想法了。如果我可以提供更多信息,请告诉我!
如果答案很明显,我很抱歉问这个问题。
最佳答案
查看您的 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/