Forum Discussion

jdwather's avatar
jdwather
Contributor
7 years ago
Solved

How to pass to the next test in the script after an error occurs.

Hi I performed my tests using two levels of test list, where in the first level has the procedure call containing all tests of a particular module and when executing an item in this list, inside thi...
  • tristaanogre's avatar
    tristaanogre
    7 years ago

    Keep in mind "catch" won't catch a simple Log.Error.  That's not an "exception", that's just writing an error to the test log.  There are other things that TestComplete writes out to the test log as errors that also are not exceptions... for example, if a checkpoint fails, that logs an error but it's not going to be trapped by try/catch logic.  This is why, for my test cases, when I want to actually halt the test case and "skip" to the next one, I explicitly raise an exception so that it "bubbles" up to my try/catch logic.  As mentioned, this is probably going to take a bit of re-engineering on your part where you more explicitly control your test cases with this kind of logic. 

     

    As for what you should do with your "OnLogError", I think you need to pull the code out of there that executes the next test case... that really is a bad use of that event handler.  Keep the handler reduced down to handling specific actions that need to be done when logging the error, not in controlling test flow.

     

    As for example, here's kind of a roughed out pseudo-code of what would be done within a single for-loop:

     

    for (var i = 1; i < totalTestCases; i++){
       try{
           testcase[i].Run();
       }
       catch(exception){
            Log.Error('The test case with name ' + testcase[i].Name + ' failed with the following error: ' + exception.message);
       }
    }
    
    //example test cases
    
    function testcase1(){
       //Do something
       //if the test fails
       throw Error('The test case failed because of blah blah blah');
    }
    
    function testcase2(){
       //Do something
       //if the test fails
       throw Error('The test case failed because of blah blah blah');
    }