Can i stop the test if an error is encountered

Posted by Bharani Ranganath on 13-Jun-2016 00:47

Hi ,

    I want to stop the execution of tests if an error occurs in the first test in ABL Unit Testing. Is this possible ?

All Replies

Posted by DivyaTheja on 13-Jun-2016 07:50

As far as i know, the only possibility is to use haltOnError option when running ABLUnit tests from ANT.

Posted by Peter Judge on 13-Jun-2016 09:08

you could catch errors in your test, and in the CATCH block, call QUIT.

Posted by Bharani Ranganath on 15-Jun-2016 05:52

I am trying to run a test, catch the error and calling QUIT. QUIT is actually stopping the other tests to run, but the log file is not getting generated, It just says .cls failed. Will this error (the error from the first test ) be logged in a separate file ?

Posted by Brian K. Maher on 15-Jun-2016 05:58

That is expected.  The QUIT statement literally quits (terminates / shuts down) the progress session.

Posted by Bharani Ranganath on 15-Jun-2016 06:02

Is there a way wherein i stop the execution of the remaining tests if one test/condition fails - after logging the error using assert statement ?

Posted by Brian K. Maher on 15-Jun-2016 06:16

In your previous post you state that QUIT is stopping the execution but the log file is not getting generated.  This sounds like QUIT is doing what you want (stop the execution of the remaining tests) and that your real problem is not getting a log file.  Why don’t you post your code so we can see what you are actually doing.

Posted by Bharani Ranganath on 15-Jun-2016 06:31

@test.
METHOD PUBLIC VOID ValidateUser():

IF NOT ValidateUserCredentials(OUTPUT cError) THEN DO:

          Assert:RaiseError(cError).

          QUIT. //quit/return

       END.

/*        CATCH err AS appError :                                         */

/*           DO piLoop = 1 TO err:NumMessages:                            */

/*                Assert:RaiseError(err:GetMessage(piLoop)').    */

/*                LEAVE.                                                  */

/*            END.                                                        */

/*            GarbageCollectorHelper:DeleteObject(oContextDatasetFactory).*/

/*           // QUIT .                                                    */

/*        END CATCH.                                                      */

ValidUserCredentails is a method which will check for valid credentials and returns an error. If there is an error, i want to stop the other methods from running. I tried using assert:equals but no change. When i run the build.xml , i get the message " build.xml:14: com.progress.openedge.ant.ablunit.ABLUnitTaskException: CompanyUnitTest.cls failed"  and i dont see the log in the results folder

Posted by Brian K. Maher on 15-Jun-2016 06:36

The commented code in the catch block ... when you uncomment that does the code still quit like you want?  Please note that I am not asking if it writes to the log, all I want to know is if it quits like you want.

Posted by Bharani Ranganath on 16-Jun-2016 07:48

I tried the same code uncommenting the catch block, now it does not quit, and continues with rest of the test cases .

Here is the code :

   METHOD PUBLIC VOID ValidateUser():

       IF NOT ValidateUserCredentials(OUTPUT cError) THEN DO:

           Assert:RaiseError(cError).

           QUIT.

       END.

        CATCH err AS appError :                                        

           DO piLoop = 1 TO err:NumMessages:                            

               Assert:RaiseError(err:GetMessage(piLoop)).    

               LEAVE.                                                  

           END.                                                        

           GarbageCollectorHelper:DeleteObject(oContextDatasetFactory).

           QUIT .                                                    

       END CATCH.                                                    

   END METHOD.

and the output after build is :

<?xml version="1.0" ?>

<testsuites errors="0" failures="12" name="ABLUnit" tests="22"><testsuite name="Base/Company/Companies/CompanyUnitTest.cls" tests="22" time=".336"><testcase name="ValidateUser" status="Failure" time=".013"><failure message="Unknown User/Company Parameters">RaiseError OpenEdge.Core.Assert at line 918  (OpenEdge/Core/Assert.r)

ValidateUser Base.Company.Companies.CompanyUnitTest at line 453  

RunTests OpenEdge.ABLUnit.Runner.ABLRunner at line 150  (OpenEdge/ABLUnit/Runner/ABLRunner.r)

ABLUnitCore.p at line 72  (ABLUnitCore.r)</failure></testcase><testcase name="CreateInvalid" status="Success" time=".006"/><testcase name="InValidCompany" status="Failure" time=".064"><failure message="Record already exists with this identity (5)">RaiseError OpenEdge.Core.Assert at line 918  (OpenEdge/Core/Assert.r)

InValidCompany Base.Company.Companies.CompanyUnitTest at line 549  

Not sure where i am going wrong !!!

Posted by Brian K. Maher on 16-Jun-2016 07:52

What happens if you remove the LEAVE statement?  It isn’t needed.

Posted by Bharani Ranganath on 17-Jun-2016 00:27

Removed LEAVE , but still doesn't QUIT . Records the error message and continues with rest of the tests.

This thread is closed