Documentation‎ > ‎1 min. tutorial‎ > ‎

1 min. tutorial (3/3)

 << Previous

Code your test

The test routine should verify that when calling PR-ORDER with a COMMAND-ORDER in which:
FROM-COUNTRY is France and TO-COUNTRY is Italy then DELIVER-TAX is set to 120€.

To implement this create a routine called "TS000011.cbl" that is using a 2 CBU copybooks (CBUC0002 in the working storage section and CBUC0000 in the linkage section):

 PROGRAM-ID. TS000011.
 ENVIRONMENT DIVISION.
 CONFIGURATION SECTION.
 DATA DIVISION.

 WORKING-STORAGE SECTION.
     COPY
CBUC0002.

     01 COUNTRY-LIST .
           05 ITALY PIC X(2) VALUE "IT".
           05 FRANCE PIC X(2) VALUE "FR".
     01 TAX-FRIT PIC 9(4) VALUE 120.
     01 ORIGINAL-PRICE PIC 9(4) VALUE 156.
     01 FINAL-PRICE PIC 9(4).
          
 LINKAGE SECTION.
     COPY CBUC0000.

In the linkage section declare a COMMAND-ORDER having the same structure than in the routine PR-ORDER.
To be able to use this variable through different tests, it should be a sub-level of CBU-user-context variable which is a reserved CBU variable.
The 'CBU-user-context' is given as an input parameter with 'CBU-ctx' variable (this last one is an internal parameter used by CBU engine: never modify it)  .

 
**********************************************************
* USER BUSINESS CONTEXT FOR EXECUTION
**********************************************************
     01 CBU-user-context.
        02 COMMAND-ORDER.
           10 PRODUCT-INFORMATION.
                15 PRODUCT-CODE PIC X(8).
                15 PRODUCT-SIZE PIC 9(1).
                15 PRODUCT-PRICE PIC 9(4).          
           10 DELIVER-INFORMATION.
                15 FROM-COUNTRY PIC X(2).
                15 TO-COUNTRY PIC X(2).
                15 DELIVER-TAX PIC 9(4).
           10 ORDER-PRICE PIC 9(4).         
     
 

  PROCEDURE DIVISION USING CBU-ctx CBU-user-context.

* Initialize a command order  
   MOVE ITALY TO TO-COUNTRY.
   MOVE FRANCE TO FROM-COUNTRY.  
   MOVE "S99MLP15" TO PRODUCT-CODE.
  
* Call the COBOL program that set deliver taxes       
   CALL "PR-ORDER" USING  COMMAND-ORDER  COUNTRY-LIST.
  
* Add Assertion for deliver tax  
   MOVE "FR => IT:TAX=120" TO CBU-ASSERT-NAME.
   SET CBU-ASSERT-EQUAL TO TRUE.
   SET CBU-ASSERT-INT TO TRUE.
   MOVE 120 TO CBU-ASSERT-EXPECTED-INT.
   MOVE DELIVER-TAX TO CBU-ASSERT-ACTUAL-INT.
   CALL CBU-assert USING CBU-ASSERT-CALL-INTERFACE CBU-ctx.         
   GOBACK.

Now let's run our test calling CBUP0005. The tests result is stored in CBUPRINT.DAT file:

^L^@************************************************************************************************************************
^@COBOL UNIT : A COBOL FRAMEWORK FOR UNIT TESTS.
^@************************************************************************************************************************
^@

^@COBOL UNIT Current release  : REL 1.00
^@COBOL UNIT Release date     : 2009-10-31
^@Language used for Logging   : EN
^@Verbosity Level of Log      : 1
^@End of the 'Testing Strategy Set up' Phase
^@Starting the 'Test Execution' Phase
^@|--- SUITE ' SUITE-DELIVERY-COST ' Running
^@|--- | TEST ' FRANCE-TO-ITALY ' Running
^@|    |- Assert ' FR => IT:TAX=120 ' success
^@|    |==> Test ' FRANCE-TO-ITALY ' * SUCCESS * ( 000000001 Assertions, 000000000 Failures, 0 errors).
^@|==> SUITE ' SUITE-DELIVERY-COST ' SUCCESS ( 000000000 test cases, 000000001 success, 000000000 failures, 000000000 errors)

^@******************************************************************************************************************
^@* SUCCESS * ( 000000001 Suites run, 000000001 succeed, 000000000 failed)     *
^@******************************************************************************************************************
^@( 00 min: 00 sec: 00 ms)


The Suite succeed!

 << Previous
Comments