Creating consumer-driven Contract tests by synchronizing resources

You can opt to create consumer-driven Contract tests when you synchronize resources that you created in another application with Test Integrations and APIs. If you already have created tests in the other application for your system under test and you have defined schemas and roots for messages, you can use the synchronizing feature of Test Integrations and APIs to generate Contract tests, tests, and stubs that you can run on Test Integrations and APIs.

Before you begin

You must have completed the following tasks:
  • Created tests for your system under test in another application. The tests must include messages that use a transport and you must have defined schemas and roots for the messages.
  • Read the types of resources that you can synchronize with Test Integrations and APIs. See Adding a resource.
  • Created a project. See Creating a project.
  • Opened the Synchronization view in the Architectural School perspective in Test Integrations and APIs.

Procedure

  1. Click the Create Synchronization Source icon Image of the create synchronize source icon. in the toolbar.
  2. Perform the following steps in the Create a new Synchronization Source dialog:
    Image of the create a new synchronization source wizard.
    1. Click Browse to locate the file that contains the resources to synchronize.
    2. Identify the file in the location where you saved it.
    3. Select the file, and then click Open.

      The type of the resource is automatically selected based on the resource.

    4. Enter the location of the resource in the Location field or browse to select a resource in your local system.
    5. Select or enter an environment.
    6. Click Next.
      The Generate Assets for Operations dialog is displayed.Image of the Generate assets for operations dialog box.
  3. Select any of the following actions that depends on the type of Contract testing you want to perform in Test Integrations and APIs:
    • If you want to perform consumer-driven Contract testing, go to Step 4.
    • If you want to perform producer-driven Contract testing, go to Step 5.
  4. Perform the following steps in the Generate Assets for Operations dialog:
    1. Click Contract Tests to generate the Contract tests for operations from the resources synchronized.
      Note: The default type of tests that are created is Tests.
    2. Select the tests that you want to generate by clicking the box against each test or select the Create Tests in the header column to generate all the tests.
    3. Create Next.

      Test Integrations and APIs determines if the schemas are defined for messages in the resources and decides the number of operations and Contract tests that must be generated.

      Image of the test generation in progress.

    4. Click Next on each of the dialog boxes that display the test being generated.

      After all the tests are generated from the resources, the Summary dialog is displayed.Image of the test generation summary dialog.

    5. Click Finish.

      The Test Factory view is displayed that shows all the operations created from the resources synchronized. The tests are created under operations.

  5. Perform the following steps in the Generate Assets for Operations dialog:
    1. Click Contract Tests to generate the Contract tests for operations from the resources synchronized.
      Note: The default type of tests that are created is Tests.
    2. Select the tests that you want to generate by clicking the box against each test or select the Create Tests in the header column to generate all the tests.
    3. Select the stubs that you want to generate by clicking the box against each stub or select the Create Stubs in the header column to generate all the stubs.
    4. Create Next.

      Test Integrations and APIs determines if the schemas are defined for messages in the resources and decides the number of operations, tests, and stubs that must be generated.

    5. Click Next on each of the dialog boxes that display the test being generated.

      After all the tests are generated from the resources, the Summary dialog is displayed.Image of the test generation summary dialog.

    6. Click Finish.

      The Test Factory view is displayed that shows all the operations created from the resources synchronized. The tests are created under operations.

Results

You have successfully created Contract tests, tests, and stubs under operations from the synchronized resources.

What to do next

You can perform the following tasks:
  • Verify whether the test is a Contract test by performing the following steps:
    1. Click the test in the Test Factory view to open the test steps in the Test Lab view.
    2. Click the Reply or Subscribe action.
      The message is displayed in the Message Editor.
      Image of the message in the Message Editor.
    3. Check if any of the message elements have a value as Validate Against Contract.

      If any of the message elements display this value, then the test created is a Contract test.

  • Run the Contract test in any of the following methods:
    • Right-click the Contract test, and then click the Run icon Image of the Run icon..
    • Select the Contract test, and then click the Run icon Image of the Run icon. in the toolbar.
  • View in the console log, after the test runs that the incoming messages are validated against the contract.