Unit-Testing Framework - Limit db connect/disconnect calls

When unit-testing code, when I want to write code for db connect and db disconnect in the current framework, there is no place holder where we can do this a single time for all the test cases for one program.

In the unit-testing framework we have entry points which define the program flow, I’ve mentioned the entry points below in the order that it is executed:

  1. entry MFU-TC-METADATA
  2. entry MFU-TC-PREFIX
  3. entry MFU-TC-SETUP-PREFIX
  4. entry MFU-TC-TEARDOWN

All these entry points are executed each time a test case is run, so when we write a code for db connect and disconnect in the test program( in any one of the above sections), and I’ve 10 rows in the input CSV file, then the db connect and db disconnect statements will be executed 10 times.This will cause a performance issue down the line when we are running 100s of test cases for a single program. Is there a way we can control the flow or have a section which is executed only once before and after execution of all test cases written?

  • Hi  ,

     

    My apologies for the delay in responding. You are correct that the Unit Testing framework does not directly support the type of pre-all-tests or post-all-tests event that you would like to use for one-time actions like connecting to/disconnecting from a database. I've received a suggestion for an option that might provide a way to do what you want. I'll provide an update here after I've had a chance to try it out.

  • Verified Answer

    I was able to create an example, based on the example in the documentation for data-driven Unit Tests that demonstrates one way that you could do this.

    I have attached a zip file here. Unzip it to a folder on your system then open up a Visual COBOL command prompt and change directories to that folder and run the doit.bat file to compile and run the test.

    Since the test harness program is called once for each record in the csv file and the test harness maintains state between the calls you can add a header and trailer record to the csv file which will tell the program that it should do a connect or disconnect. The connect and disconnect will also be part of the test results.

    My example here uses a simple external file instead of a database but it should work the same way. When the CONNECT record is passed to the program it will perform a paragraph that opens the file for output and writes a record to it. The DISCONNECT record will write a record and close the file. The actual test being called will write records to the file without the need to open and close it each time.

    I hope this workaround helps you...

    Thanks.

    UnitTestData.zip
  • Thanks very much for the workaround!  We will try it out and advise.

  • Just to follow-up on this topic, Development will be adding new functionality to the Unit Testing framework which will allow for setup and teardown entry points that will be called at the beginning and end of a data-driven unit test run. This will be included in the next major product release which is 6.0 due to be GA in summer.

    - MFU-TC-SETUP-DD-PREFIX - Prefix for the data driven setup entry-point
    - MFU-TC-TEARDOWN-DD-PREFIX - Prefix for the data driven teardown entry-point

    entry MFU-TC-SETUP-DD-PREFIX & "TESTFLYER".
          perform 100-open-file
          goback.
     
    entry MFU-TC-TEARDOWN-DD-PREFIX & "TESTFLYER".
          perform 200-close-file
          goback.