gpt4 book ai didi

c# - 如何使用 Assert 验证 MSTest 是否抛出了异常?

转载 作者:IT王子 更新时间:2023-10-29 03:27:03 25 4
gpt4 key购买 nike

如何使用 Assert(或其他测试类)验证在使用 MSTest/Microsoft.VisualStudio.TestTools.UnitTesting 时是否抛出了异常?

最佳答案

对于“Visual Studio Team Test”,您似乎将 ExpectedException 属性应用于测试方法。

此处文档中的示例:A Unit Testing Walkthrough with Visual Studio Team Test

[TestMethod]
[ExpectedException(typeof(ArgumentException),
"A userId of null was inappropriately allowed.")]
public void NullUserIdInConstructor()
{
LogonInfo logonInfo = new LogonInfo(null, "P@ss0word");
}

关于c# - 如何使用 Assert 验证 MSTest 是否抛出了异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/933613/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com