locked
How to catch AssertionException and Test should fail RRS feed

  • Question

  • Hi,

    I want to handle Assert.Fail("msg") exception and test should fail as well.

    Thursday, April 26, 2018 2:16 PM

All replies

  • Hi,

    [TestMethod]
            public void TestMethod1()
            {
               
                try
    
                {
    
                    Assert.Fail("Failed because something went wrong.");
    
                }
    
                catch (AssertionException ex)
    
                {
    
                    Debug.WriteLine(string.Format("Something specific went wrong.", ex));
    
                    throw;  
    
                }
    
            }

    Best regards,

    Joyce


    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, April 27, 2018 6:34 AM