シンプルなテスト ケース例

自己完結型テスト フィクスチャとして完全な COBOL プログラムを使用する単体テストの例には、テスト ケース ロジックとテスト対象データが含まれます (テスト環境のセットアップとティアダウンを含む)。

以下の例では、ファイルへの書き込みが可能かどうかをテストします。ファイルへの書き込みに問題がある (ファイルが存在しない、またはロックされている) 場合、テストは失敗します。

プログラムを .dll (Windows) または .so (UNIX) (「テストのコンパイル」参照) にコンパイルし、得られたテスト スイートを実行します (「テストの実行」参照)。

      $set case
       program-id. TestCases.
       environment division.
       input-output section.
       file-control.
       select cust assign to 'cust.txt'
         organization is line sequential.
       data division.
       file section.
       fd cust.
       01 cust-file.
          03 customer-id    pic 9(5).
          03 customer-info  pic x(65).

       working-storage section.
       copy "mfunit.cpy".
       procedure division.
       goback.

       entry MFU-TC-PREFIX & "FullTestCase".    *> the test case
       move 0 to customer-id
       perform 100 times
        add 1 to customer-id
        move "A customer" to customer-info
        write cust-file
       end-perform
       goback.

       entry MFU-TC-SETUP-PREFIX & "FullTestCase".  *> the test case setup
       open output cust
       goback

       entry MFU-TC-TEARDOWN-PREFIX & "FullTestCase". *> the test case teardown
       close cust
       goback

       end program.