Nunit ExpectedException是否正常工作? [英] Is Nunit ExpectedException Working Correctly?
问题描述
在设置一些命令行脚本来为我正在研究的项目测试我的NUnit测试套件时,我开始遇到问题.
I started having problems earlier when setting up some command line scripts to test my NUnit suite of tests for a project I am working on.
我注意到,在Visual Studio
或Xamarin
中运行测试时,结果是我期望的,但是当在命令行中使用nunit-console
(mac v2.4.8
)运行时,它不会失败测试.
I noticed that when running the tests in Visual Studio
or Xamarin
that the results are what I expected, but when running from the command line with the nunit-console
(mac v2.4.8
) it doesn't fail some of the tests.
所有失败的测试(在控制台中不会失败)均使用[ExpectedException]
属性(均具有类型和一般属性).更改为使用Assert.Throws<>
时,它可以在IDE和命令行中正常工作.
All the of the tests that are failing that don't fail in the console use the [ExpectedException]
attribute (both with a type and in general). When changing to use Assert.Throws<>
it works correctly in both the IDEs and the command line.
这是Nunit或我拥有的特定版本/平台的错误吗?
Is this a bug with Nunit or the particular version/platform I have?
推荐答案
这是unit-console
2.4.8中的一个错误,并且正如一位评论者所建议的,与VS测试运行程序无关.我在cmd行上使用3.x来解决此问题,方法是将它添加到我的Makefile中,并进行"make test",以进行本地nuget安装.
It is a bug in unit-console
2.4.8 and has nothing to due with VS test runner as one commenter suggested. I use 3.x on the cmd-line to work around it by doing a local nuget install as I add this into my Makefile and can do a 'make test'.
nunit-console -nologo -labels.dll
nunit-console -nologo -labels except.dll
***** except.Test.ExpectedException
***** except.Test.ExpectedNotSystemException
***** except.Test.ExpectedNotTypeOfSystemException
***** except.Test.NotExpectedException
Tests run: 4, Failures: 1, Not run: 0, Time: 0.106 seconds
Test Case Failures:
1) except.Test.NotExpectedException : System.Exception : Stackoverflow
at except.Test.NotExpectedException () [0x00006] in /Users/sushi/code/XamTests/except/except/Test.cs:33
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00038] in /private/tmp/source-mono-mac-4.2.0-branch-c6sr1/bockbuild-mono-4.2.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.2.2/mcs/class/corlib/System.Reflection/MonoMethod.cs:295
本地3.0.1安装和测试(正常工作):
nuget install nunit.runners
nuget install nunit.runners
./NUnit.Console.3.0.1/tools/nunit3-console.exe除了.dll
./NUnit.Console.3.0.1/tools/nunit3-console.exe except.dll
NUnit Console Runner 3.0.5813
~~~
Errors and Failures
1) Failed : except.Test
One or more child tests had errors
2) Failed : except.Test.ExpectedNotSystemException
An unexpected exception type was thrown
3) Failed : except.Test.ExpectedNotTypeOfSystemException
An unexpected exception type was thrown
4) Error : except.Test.NotExpectedException
Test Run Summary
Overall result: Failed
Tests run: 4, Passed: 1, Errors: 1, Failures: 2, Inconclusive: 0
Not run: 0, Invalid: 0, Ignored: 0, Explicit: 0, Skipped: 0
Start time: 2016-01-26 23:09:56Z
End time: 2016-01-26 23:09:56Z
Duration: 0.117 seconds
测试案例:
using NUnit.Framework;
using System;
namespace except
{
[TestFixture ()]
public class Test
{
[Test ()]
[ExpectedException]
public void ExpectedException ()
{
throw new Exception ("Stackoverflow");
}
[Test ()]
[ExpectedException("System.DivideByZeroException")]
public void ExpectedNotSystemException ()
{
throw new Exception ("Stackoverflow");
}
[Test ()]
[ExpectedException(typeof(DivideByZeroException))]
public void ExpectedNotTypeOfSystemException ()
{
throw new Exception ("Stackoverflow");
}
[Test ()]
public void NotExpectedException ()
{
throw new Exception ("Stackoverflow");
}
}
}
这篇关于Nunit ExpectedException是否正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!