【发布时间】:2017-05-09 05:03:55
【问题描述】:
我正在为 core 应用程序编写单元测试。我试图检查我的班级是否抛出异常。但是 ExpectedException 属性会抛出编译异常:
错误 CS0246 类型或命名空间名称“ExpectedException”不能 被发现(您是否缺少 using 指令或程序集 参考?)EventMessagesBroker.Logic.UnitTests..NETCoreApp,Version=v1.0
我的代码:
[Fact]
[ExpectedException(typeof(MessageTypeParserException))]
public void TestMethod1_Error_twoMathces()
{
var message = "some text";
var parser = new MessageTypeParser();
var type = parser.GetType(message);
Assert.Equal(MessageType.RaschetStavkiZaNalichnye, type);
}
那么,有没有正确的方法来实现呢?
【问题讨论】:
-
不读xunit.github.io/docs/comparisons.html就不要使用xunit@
-
晚了 3 年...ExpectedException 来自 MSTest Nuget...没有任何运气交叉使用 Nuget w/Xunit
标签: unit-testing asp.net-core .net-core xunit xunit.net