Creating and Running an Automatic Unit Test on a Data Class
This document provides information on how to create and run an automatic unit test on a specific data class.
The process described below demonstrates how to create a simple script file to:
To do so:
############################################################# AXUNIT TEST SCRIPT## Data Class - MYCLASS ## Test Scope – Basic#############################################################Call TESTSUITEEndFunprog TESTSUITE()# Start the test suiteCall TESTSUITE_START("MYCLASS", "MYRECORD TEST") From AXUNITCall ADD_TESTCASE("MYCLASS_AINSERT","Insert a new record",2) From AXUNITCall ADD_TESTCASE("MYCLASS_AREAD","Read a record", 8) From AXUNITCall ADD_TESTCASE("MYCLASS_AUPDATE","Update a record", 3) From AXUNITLocal Clbfile RESULT_SUITERESULT_SUITE=func AXUNIT.RUN_TESTSUITE("MYCLASS", "MYRECORD TEST")End RESULT_SUITE
Subprog SETUPLocal Integer II=func CLEANUP("EXISTINGRECORD")ENDFUNCFunprog CLEANUP(NUMMBR)Value Char NUMMBRLocal Integer ILocal File MYTABLE [TABLE ALIAS]Trbegin [TABLE ALIAS]Delete [RECORDNAME] Where MYPROP1 = NUMMBRI+=adxdlrecCommitClose File [TABLE ALIAS]End I
Subprog MYCLASS_AINSERTLocal Instance MYRECORD Using C_MYCLASSMYRECORD = NewInstance C_MYCLASS AllocGroup NullLocal Integer OK OK = fmet MYRECORD.AINIT()Call CHECK_EQUAL(OK,[V]CST_AOK) From AXUNITMYRECORD.MYPROP1 = "EXISTINGRECORD"MYRECORD.MYPROP2 = "abcdefghij" MYRECORD.MYPROP3 = "nnnnnnnnnn" ...MYRECORD.MYPROP8 = [dd/mm/yyyy] OK = fmet MYRECORD.AINSERTCall CHECK_EQUAL(OK,[V]CST_AOK) From AXUNITFreeGroup MYRECORDEnd
Subprog MYCLASS_AREADLocal Instance MYRECORD Using C_MYCLASSMYRECORD = NewInstance C_MYCLASS AllocGroup nullOK= fmet MYRECORD.AREAD("EXISTINGRECORD")Call CHECK_EQUAL(OK,[V]CST_AOK) From AXUNITCall LOG_LINE("Verify the values read") From AXUNITCall CHECK_EQUAL(MYRECORD.MYPROP1,"EXISTINGRECORD") From AXUNITCall CHECK_EQUAL(MYRECORD.MYPROP2,"abcdefghij") From AXUNITCall CHECK_EQUAL(MYRECORD.MYPROP3,"nnnnnnnnnn") From AXUNIT...FreeGroup MYRECORDEnd
Subprog MYCLASS_AUPDATELocal Instance MYRECORD Using C_MYCLASSMYRECORD = NewInstance C_MYCLASS AllocGroup NullOK= fmet MYRECORD.AREAD("EXISTINGRECORD")Call CHECK_EQUAL(OK,[V]CST_AOK) From AXUNITMYRECORD.MYPROP2 = "Changed by AXUNIT"OK= fmet MYRECORD.AUPDATECall CHECK_EQUAL(OK,[V]CST_AOK) From AXUNITCall LOG_LINE("Verify values changed") From AXUNITCall CHECK_EQUAL(MYRECORD.MYPROP2,"Changed by AXUNIT") From AXUNITFreeGroup MYRECORDEnd
=> func QLFXL_CLASS.TESTSUITENote: This code creates trace file "QLFXL_CLASS_XNAME" where "XNAME" is the name of the Sage X3 user who ran the script.
This example describes the creation of an "AXUNIT" script file that tests the "AINSERT", "AREAD", and "AUPDATE" methods available in the "XLMBOOK" data class. The "XLMBOOK" data class stores records of books in a Library Management System application.
An example trace file is also provided to show the results of this script.
This script will allow you to:
Note: This script file has been created using the Eclipse IDE (Indigo release) editor.
############################################################# AXUNIT TEST SCRIPT## Data Class - XLMBOOK ## Test Scope – Basic############################################################# Call TESTSUITEEndFunprog TESTSUITE()# Start the test suiteCall TESTSUITE_START("XLMBOOK", "XLMBOOK TEST") From AXUNITCall ADD_TESTCASE("XLMBOOK_AINSERT","Insert a new Library Book",2) From AXUNITCall ADD_TESTCASE("XLMBOOK_AREAD","Read a book", 8) From AXUNITCall ADD_TESTCASE("XLMBOOK_AUPDATE","Update a book", 3) From AXUNITLocal Clbfile RESULT_SUITERESULT_SUITE=func AXUNIT.RUN_TESTSUITE("XLMBOOK", "XLMBOOK TEST")End RESULT_SUITEThis code will run three test sub routines:
Subprog SETUPLocal Integer II=func CLEANUP("B20")ENDFUNCFunprog CLEANUP(NUMMBR)Value Char NUMMBRLocal Integer ILocal File XLMBOOK [XLMBOOK]Trbegin [XLMBOOK]Delete [XLMBOOK] Where IDBOOK = NUMMBRI+=adxdlrecCommitClose File [XLMBOOK]End I
Subprog XLMBOOK_AINSERTLocal Instance MYBOOK Using C_XLMBOOKMYBOOK = NewInstance C_XLMBOOK AllocGroup NullLocal Integer OK OK = fmet MYBOOK.AINIT()Call CHECK_EQUAL(OK,[V]CST_AOK) From AXUNITMYBOOK.IDBOOK = "B20"MYBOOK.TITLE = "Auto Generated Book" # A data typeMYBOOK.ISBN = "12345678910" # DCT data typeMYBOOK.BKPRICE = 20.00 # DCB data typeMYBOOK.BKGENRE = 4# M 13001 data type#BOOK.BKSTATUS = "2" # M 13002 data typeMYBOOK.DDC = "654"# A data typeMYBOOK.DATEPUR = [15/03/2013] # D data typeOK = fmet MYBOOK.AINSERTCall CHECK_EQUAL(OK,[V]CST_AOK) From AXUNITFreeGroup MYBOOKEnd
Subprog XLMBOOK_AREADLocal Instance MYBOOK Using C_XLMBOOKMYBOOK = NewInstance [MYB] AllocGroup NullOK= fmet MYBOOK.AREAD("B20")Call CHECK_EQUAL(OK,[V]CST_AOK) From AXUNITCall LOG_LINE("Verify the values read") From AXUNITCall CHECK_EQUAL(MYBOOK.IDBOOK,"B20") From AXUNITCall CHECK_EQUAL(MYBOOK.TITLE,"Auto Generated Book") From AXUNITCall CHECK_EQUAL(MYBOOK.ISBN,"12345678910") From AXUNITCall CHECK_EQUAL(MYBOOK.BKPRICE,20.00 ) From AXUNITCall CHECK_EQUAL(MYBOOK.BKGENRE,4) From AXUNITCall CHECK_EQUAL(MYBOOK.BKSTATUS,1) From AXUNITFreeGroup MYBOOKEnd
Subprog XLMBOOK_AUPDATELocal Instance MYBOOK Using C_XLMBOOKMYBOOK = NewInstance C_XLMBOOK AllocGroup NullOK= fmet MYBOOK.AREAD("B20")Call CHECK_EQUAL(OK,[V]CST_AOK) From AXUNITMYBOOK.TITLE = "Changed by AXUNIT"OK= fmet MYBOOK.AUPDATECall CHECK_EQUAL(OK,[V]CST_AOK) From AXUNITCall LOG_LINE("Verify values changed") From AXUNITCall CHECK_EQUAL(MYBOOK.TITLE,"Changed by AXUNIT") From AXUNITFreeGroup MYBOOKEnd
=> func QLFXL_BOOK.TESTSUITETrace file "QLFXL_BOOK_XJM" is created in Sage X3, with "XJM" being the name of the Sage X3 user that ran the script. The user name was set when the Eclipse project was created.
2013-08-05T16:56:49.713: Start suite - QLFXL_BOOK - XLMBOOK - XLMBOOK TEST2013-08-05T16:56:49.718: Start test case - Insert a new Library Book1.1 - check equal - OK: 01.2 - check equal - OK: 0success=2, failure=0, elapsed=40ms2013-08-05T16:56:49.758: Start test case - Read a book2013-08-05T16:56:49.768: Verify the values read2.1 - check equal - OK: 02.2 - check equal - OK: 'B20'2.3 - check equal - OK: 'Auto Generated Book'2.4 - check equal - OK: '12345678910'2.5 - check equal - OK: 202.6 - check equal - OK: 42.7 - check equal - OK: 1success=7, failure=0, elapsed=13msMismatch number of assertions: expected 8 got 72013-08-05T16:56:49.772: Start test case - Update a book2013-08-05T16:56:49.795: Verify values changed3.1 - check equal - OK: 03.2 - check equal - OK: 03.3 - check equal - OK: 'Changed by AXUNIT'success=3, failure=0, elapsed=25ms