MSTEST - Continued after confirmation failed

I am wondering if there is an easy way to end the test after Assert failed. We used Galileo for all of our automated tests, but we moved the Visual Studio Test framework. We had a method that would let the test fail, but go ahead.

public static bool DoAssertAndContinue(Action assert) { try { assert(); return true; } catch (AssertionException ae) { ConfigContext.WriteLine(ae.Message); return false; } } 

This is what we used before ... and it will be called like this:

 assertionResults.Add(Automation.Utils.CommonMethods.DoAssertAndContinue(() => Assert.IsTrue(detail.ValidateName(boo, urns)))); 

I'm just trying to find a better way to imitate what was before without refactoring all our tests.

+4
source share
3 answers

Instead of an AssertionException, you should now catch a UnitTestAssertException , which is the base exception for all mstest assert errors.

+4
source

You can also use Try / Catch in MSTest. In the Catch block, you can catch a specific error and print it using Console.Write to find out about the error. I would recommend you study this thread for more details.

EDIT 1: Personally, I don't use try / catch to pass my test method. I am writing a test method to find a defect in the actual product. Therefore, if you expect your calling method to give you a specific exception, I would suggest using the ExpectedException attribute. This applies if you are using your test method for individual test data.

Now, if you want to pass some test data to your test method. Then I would suggest going for test cases with data. Here you can store all your test data inside XML or XLS or in a database. Then, using this input file, you can feed some test data into your test method. Try not to use try / catch here for any test data if your invocation method sends you some kind of exception, and then see if MSTest can handle it and move on to the next test data or not. If it moves, then in the test results window you can see why your method failed for these specific test data. For a data-based concept, see Link

+1
source

The MsTest structure MsTest an exception if the statement fails. Distributing this method from the unit test method is what causes the test to fail. If you want to continue a failed statement, you just need to handle this exception and prevent it from slipping away from the method.

0
source

Source: https://habr.com/ru/post/1396525/


All Articles