How can I test for an expected exception with a specific exception message from a resource file in Visual Studio Test?

前端 未结 7 1934
广开言路
广开言路 2020-12-13 09:11

Visual Studio Test can check for expected exceptions using the ExpectedException attribute. You can pass in an exception like this:

[TestMethod]
[ExpectedExc         


        
7条回答
  •  春和景丽
    2020-12-13 09:41

    If you switch over to using the very nice xUnit.Net testing library, you can replace [ExpectedException] with something like this:

    [Fact]
    public void TestException()
    {
       Exception ex = Record.Exception(() => myClass.DoSomethingExceptional());
       // Assert whatever you like about the exception here.
    }
    

提交回复
热议问题