Monday, 13 February 2017

Exception handling in Xunit test case in C#





        [Fact]
        public void TestControllerTests()
        {
               Assert.ThrowsAny<ArgumentNullException>(() => new TestController(null, null));
             / / OR

          Exception ex = Assert.Throws<ArgumentNullException>(() =>
                                                                                                new TestController(null, null));
          Assert.Equal("Error message by Exception  class", ex.Message);
        }



Note => We can also use instated of  "ArgumentNullException" to Exception class or some costume class to check Exception  in xunit test case.

No comments:

Post a Comment