5

I have a suite of automated test cases, around 50 in total.

When one of my tests fails, an exception is caught and an error message is displayed. However, since all test cases are executed sequentially, all other tests will not be executed.

How do I ensure subsequent tests are run even if a test fails?

4 Answers 4

4

These things are called test attributes. For MSTest and Nunit they have there own test attributes, Only thing is you have to set the attributes in the correct way. Think wisely when you use TestInitialise and TestCleanup. These things are available to to solve the issues like yours and to minimize the automation run time.

3

Any good automation tool should have a setting that allows you to stop on error, log warning on error, or ignore error. If your test suite is built such that the scripts are independent and can be run in any order, you can set the tool to log a warning on error and continue. If your scripts are built and ordered such that one sets the state for the next, you're stuck with stopping as soon as the first error is encountered or you risk having the system in an unknown or unready state for the scripts following the failure.

If you must perform setup for a particular script, you might consider performing the setup & teardown either in separate scripts wrapping the desired check script and setting that trio as a separate suite. The benefit is that you will get more of your scripts running in a single session. The downside is that if there is an error in the setup script your check script will still not run.

2

You need to implement some kind of test cleaning up mechanism:

  • Before a test is executed, pre-configure your environment
  • A test is executed
  • Test finishes, cleaning up, e.g. configure your environment back to what it was; delete objects you created for this test case
  • Test fails for any reason, cleaning up, configure your environment back to what it was and delete any objects you created for this test case
  • Log your testing results
  • Proceed to the next test case. You have not specified your testing tool, testing environment or programming language, so I can not give you any specific advice. If you are using some kind of testing suite, there is normally an option that you can choose between stop the whole suite when there is a failure or proceed to next test case when there is a failure. If you are doing everything by scripting, then you need to catch your failure and proceed to your next test case within your test framework. Again, I can not tell you how to do this specifically.
0
2

When you try to do a assertion. If that assertion fails. AssertionException is raised. Catch that exception and you will be good to go. Better write a wrapper method around the assertion. Call that wrapper method whenever you need assertion

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.