Nav

To Configure and Write BAT Tests

To create the example project, which includes a basic project folder, configuation files, a sample "Hello, World" test, and a .yaml descriptor file, you can run the command 'bat init'. To learn how to run the sample test, you can then read Execute BAT Tests.

Alternatively, if you want to set up a basic project yourself, you can follow the steps in this procedure:

  1. Create a directory for the configuration YAML, for example /api-monitoring and a subdirectory for the tests, for example /tests.

  2. Create a minimal bat.yaml that is the manifest file for testing. For example, the bat.yaml for this procedure lists two test files:

    files:
    
     - file: ./tests/step.0.dwl
     - file: ./tests/step.1.dwl
    
    suite:
      name: "hello world test suite"
  3. Save the bat.yaml at the top level of your testing directory /api-monitoring.

  4. Create a test file. For example:

    // Functional test for http://apimon.cloudhub.io
    
    import * from bat::BDD
    import * from bat::Assertions
    ---
    describe `api-mon` in [
    
      // First, get a list of users
      GET `http://apimon.cloudhub.io/users` with {
    
      } assert [
        $.response.status mustEqual 200
      ]
    
    ]

    The GET function specifies the URL of the deployed proxy you created earlier in the workflow. For example, on CloudHub, you obtain the URL from API Manager:

    bat api mgr proxy url
  5. Save the test file in the /api-monitoring/tests subdirectory as step.0.dwl.

  6. Create another test file and save it as step.1.dwl.

    // Functional test for http://apimon.cloudhub.io
    
    import * from bat::BDD
    import * from bat::Assertions
    ---
    describe `api-mon` in [
      it `assert that there are 10 users` in [
        GET `http://apimon.cloudhub.io/users` with {} assert [
          $.response.status mustEqual 200, //< ---- ASSERTION
          $.response.mime mustEqual "application/json", //< ---- ASSERTION
          log($.response.body match{case list is Array -> sizeOf(list) mustEqual 10
            else -> false}) // < ---- ASSERTION
        ]
      ]
    ]

    This test asserts that 10 is the size of the users list array returned by the API.

In this topic:

We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor advertising. You can read more and make your cookie choices here. By continuing to use this site you are giving us your consent to do this.

+