ABL Unit Testing

Posted by Bharani Ranganath on 10-Jun-2016 00:50

Hi,

    Can i have multiple Assert statements in a method (validation methods) which is called by a test case method.  I have tried and only get one Assert that gets printed. I have also tried catching the error and clearing it. 

Best Regards.

All Replies

Posted by DivyaTheja on 10-Jun-2016 01:26

Hello Bharani,

It is always good to have a single Assert per test. A test should fail for a single reason only. If you have multiple asserts in a same test, it would be difficult and confusing for you to know which assert failed.

Hope this helps,

DivyaTheja

Posted by Mike Fechner on 10-Jun-2016 01:29

100% agreement with Divya.

While it's technically possible to have multiple Assert methods in a single test, the first fails assertion will throw an error and stop the remaining assertions from executing.

Posted by Bharani Ranganath on 10-Jun-2016 01:56

Hi Divya and Mike,

  Thanks for your replies on the Assert statement. Let me explain what i am trying to do. Basically, i am trying to write a test case for the Create,Update and Delete operations as a start.  I need to create a company, modify the company and finally the delete the company.

For the creation, we have validation methods that check Name, shortname, country ,state likewise.

So in my test case, i have separate test cases for check name, short name ...... which will have an Assert statement to display the status.  So in all, i have test cases that check for valid name, in valid name, valid shortname, invalid short name likewise.  

The same test has to again run when i modify a record. So i want to include all the methods - checkname ,checkshortname ... in a separate class and in the main test case , the first test would be to instantiate the object, call the method which checks the fields. In the checkfield, i have the Assert statement, but unfortunately only one Assert gets printed . My intention is to make use of the same methods in the test case . Since this failed, i am trying to create the method names in a temp table, and have two test cases which loops through the for each and calls the methodname. I am stuck again - Is there a way i can call the method name of a class using a value from the variable.  ? 

Posted by Mike Fechner on 10-Jun-2016 06:21

I'm not able to follow your approach. But to answer your question, check the language reference for DYNAMIC-INVOKE (available since 10.2B) or the new Reflection API's added in 11.6.

Posted by Bharani Ranganath on 10-Jun-2016 06:25

Looking into it. Thanks Mike.

Posted by Bharani Ranganath on 10-Jun-2016 11:29

Hi,

I have 6 methods/tests that i want to execute multiple times. For ex: I want to run the same tests when i create a company and also when i modify the company. So i have created a temp table that will have the method names that i want to execute. The code will be somelike this this :

@test.

method ValidateCreateCompany:

for each temp table:

     dynamic-invoke(class object, temptable.methodname,value to the method,output errors).

     Assert:equals("",errors).

end.

I am expecting the Assert to log the error for each method it executes, but it is not. The first method executes and the error is displayed, but the subsequent methods will not.

This thread is closed