Previous Topic Next topic Print topic


Creating a Unit Test Library Project

The AirportDemo solution must be already open in order to run this tutorial.
Use the test creation wizard to create a test project, including a basic template linking to your application code, to help you quickly start creating tests.
  1. In Solution Explorer, double-click aircode.cbl to open it in the editor.
  2. Click beside the types and members navigational dropdown, then select main().

    The cursor is positioned in the main section of the program.

  3. Position your cursor anywhere in the main section of the program, then right-click and select Create Unit Test.

    The Create Unit Test dialog box appears.

  4. Click OK to accept all the defaults.

    A unit test project has been created in the current solution, and includes one test program (TestAircode).

  5. Double-click TestAIRCODE.cbl to open the test program in the editor.

    The following elements have been created:

    • The test case:
      entry MFU-TC-PREFIX & TEST-TESTAIRCODE.
      
        call "AIRCODE" using
                       by value lnk-function
                       by value lnk-airport1
                       by value lnk-airport2
        ...

      This section calls into the source code that you are testing, using the parameters initialized in the test setup.

    • The test case setup:
      entry MFU-TC-SETUP-PREFIX & TEST-TESTAIRCODE.
        *> Load the library that is being tested
        set pp to entry "AirportLinkLibrary" 
        ...       

      This portion of code is run before the test case, and sets a procedure pointer to the code under test. It also goes on to initialize the variables required to call into the source code.

    Tip: You could also add a test teardown section, which would run after the test case - see Elements of a Test Case. It does not matter in which order these sections appear in the file; they will be run in the correct order (setup, test case, then teardown).
Previous Topic Next topic Print topic