c# - 在 Nunit 中测试异常
问题描述
我有以下我正在尝试测试的异常
public void Land(Plane plane)
{
if (weather.Forecast() != "stormy")
{
planes.Add(plane);
Console.WriteLine($"{ plane.Name } has landed at {_AirportName}");
}
else
{
throw new Exception("It's too stormy to land");
}
}
但是我似乎找不到正确的语法来测试这个异常?通过四处搜索,我到目前为止有:
Assert.Throws(Is.TypeOf<Exception>())
.And.Message.EqualTo("Too stormy to land");
但是它说不能从用法中推断出 Throws。
任何人都可以帮忙吗?(抱歉,对 C# 很陌生!)谢谢 :)
解决方案
推荐阅读
- lambda-calculus - 如何在 lambda 演算中证明 XOR true true = false?
- python - 如何从 on_message 事件中获取 Discord 上下文对象?
- android - 我的选项卡布局 Kotlin 有什么问题?
- php - 文件上传后重定向 PHP 脚本
- azure-devops - Azure Devops 构建之间的区别 - 队列与运行管道 REST API
- java - 如何断言是否已调用 lambda
- c# - WCF。在服务端使用 Windows 凭据
- sql - sql 每月现有用户的所有历史记录
- ios - 获取 CloudKit 的“要插入的记录已存在”错误
- python - 将碎片化的 MP4 转换为 MP4