Can't we access DB tables inside @Test annotation?

Posted by shilpi.agarwal3373 on 12-May-2016 06:13


Can't we access DB tables inside @Test annotation? Scnerio is - I am writing test case in ABLUnit for suppose Customer Deletion. So i have 3 situation for deleting the customer- Customer deletion is possible only when customer is valid and no order exist for that customer.

1. Customer does not exist (invalid case)

2. Customer exist but order exist for that customer (invalid case)

3. Customer exist but no order for customer (valid case)

What I have done- I write 3 procedures and hardcode the customer number and based on that asserting the results. like-

PROCEDURE Deletecust1: /* Customer can not be deleted, Open order exist for customer */

ASSIGN iCustnum = 11.
RUN C:\rishi\test\wrk\customer_maint\procs\deletecustomer.p (INPUT iCustnum, OUTPUT chresult).
Assert:equals("Open orders exist for customer.Cannot delete.", chresult).


PROCEDURE Deletecust2: /* Customer doesn't exist */

ASSIGN iCustnum = 99910.
RUN C:\rishi\test\wrk\customer_maint\procs\deletecustomer.p (INPUT iCustnum, OUTPUT chresult).
Assert:equals("Customer deleted by some other user / Customer does not Exist.Cannot delete.", chresult).


PROCEDURE Deletecust3: /* Valid Test Case */

ASSIGN iCustnum = 3290.
RUN C:\rishi\test\wrk\customer_maint\procs\deletecustomer.p (INPUT iCustnum, OUTPUT chresult).
Assert:equals("yes", chresult).


But I do not want to use hardcoded value of Customer number, just replaced 3 procedures into one procedure by making a new table say "Testing" in the database(autodb) and write ABLUnit test case like this---


RUN C:\rishi\test\wrk1\testcasedb.p. ( writing connect statement inside this .p)

/*CONNECT C:\rishi\test\data\autodb -S 4500. */


PROCEDURE Deletecust1:

FOR EACH Testing WHERE Testing.Proc-Name = "deletecustomer.p" no-lock:
ASSIGN iCustnum = integer(testing.input-param).
RUN C:\rishi\test\wrk1\customer_maint\procs\deletecustomer.p (INPUT iCustnum, OUTPUT chresult).
Assert:equals(Testing.output-param, chresult).

So when I run this test case as ABL UNIT, i am getting following error-

"Ambiguous or unknown table Testing"

Please suggest.

All Replies

Posted by Elaine Rosenberg on 12-May-2016 06:54

Hi Shilpi,

To add the database at runtime for ABLUnit, you must modify the launch configuration to use the database connection available in Developer Studio. Even though the project has a connection to the database, it is not used at runtime unless the launch configuration has a connection. You must:

1.  Select the launch configuration for your test.

2.  Select the Database tab in the launch configuration window.

3.  Select an existing database connection.


Elaine Rosenberg

Posted by DivyaTheja on 12-May-2016 07:47

Hello Shipli,

As far as i know, in any unit testing framework, it is not recommended for unit tests to interact directly with database for fetching/modifying data.

In your case, the error is from test procedure Deletecust1. Instead of writing FOR EACH statement directly in unit test, you could write the same in a procedure file and run it from Deletecust1 test.

Hope this helps,


Posted by shilpi.agarwal3373 on 12-May-2016 23:54

Thanks a lot.

Posted by shilpi.agarwal3373 on 13-May-2016 00:02

One more question- I am writing a test case in ABL UNIT for customer deletion in which i have 3 scenerios as explained above posts. (2 invalid(customer not deleted) and 1 valid (customer should delete))

When I Run this test case as ABLUnit then it is working fine In case of success as well as failure). But when I run this test case through ANT Script, it is not showing me any failure/passed. It always shows success 0 , failure 0 and BUILD is successful even though 1 failure must occur.

My Ant Script is-

<!-- Run Test cases -->

<!-- Target for defining 'taskdef' -->

<target name="taskdef">

 <taskdef name="ablunit" classname="com.progress.openedge.ant.ablunit.ABLUnitTask" classpath="c:\abl\lib\ant-ablunit.jar" />


<!-- Target for defining 'ablunit' -->

<target name="ablunit" depends="taskdef,compile" description="run unit tests">

   <mkdir dir="results"/>

<ablunit dlc="${DLC_HOME}" environment="gui" printsummary="true" tempdir="c:\shilpi\POC\ablunit">

  <batchtest todir="results">                          

      <fileset dir="tests" includes="**/*.p" >    



      <dbinfo name="c:\rishi\test\data\autodb.db" port="4500"/>


           <pathelement path="c:\shilpi\POC\ablunit\tests" />

           <pathelement location="${DLC_HOME}\gui\" />

           <pathelement location="${DLC_HOME}\gui\" />



       <echo message="Run Test cases" />


This thread is closed