Free MuleSoft CONNECT Keynote & Expo Pass Available!

Register now+

To Run Tests in the BAT Playground

The BAT playground is a web application you can use to familiarize yourself with Behavior Driven Development (BDD) functions. The playground runs tests on the Deck of Cards API by default, but you can tweak commands to experiment and learn about BDD functions by running tests on your API using the BAT playground. In this procedure, you modify the default test, and instead, test the JSONPlaceholder API you designed earlier in this workflow.

  1. Start the BAT playground by going to the following URL:

    BAT playground

  2. Familiarize yourself with Behavior Driven Development (BDD) functions by experimenting with commands using your API in the BAT playground. For example, try altering Step 3, Setting an id with HashMap:

    • Replace the URL in the GET function with the URL of the JSONPlaceholder API that you created in a previous workflow step. For example:

      FROM: GET ``

      TO: GET ``

    • Change line 11 as follows:

      FROM: $.response.body.remaining mustEqual 52 // ←-- And a boolean assertion

      TO: $[1] mustEqual 2 // ←-- And a boolean assertion

    • Replace the context.set statements to assert that the ID at index position 2 in the array is 3:

      FROM: context.set('deck_id', $.response.body.deck_id), // ←-- Setting deck_id

      TO: $[2] mustEqual 3, // ←-- And a boolean assertion

    • Add these lines to assert that the fourth name in the array is Karianne:

      context.set('username', $.response.body.username[3]),
      $.response.body.username[3] mustMatch goodName,

      Step 3 now looks like this:

      import * from bat::BDD
      import * from bat::Assertions
      var goodName = "Karianne"
      var context = bat::Mutable::HashMap() // <--- First, the HashMap
      describe `Deck of cards` in [
        // Then we get a new deck of cards
        GET `` with {} assert [
          $.response.status mustEqual 200, // <--- Then a status assertion
          $.response.mime mustEqual "application/json", // <--- And a MIME type assertion
          $[2] mustEqual 3, // <--- And a boolean assertion
        ] execute [
          context.set('username', $.response.body.username[3]),
          $.response.body.username[3] mustMatch goodName,
          log($.response) // <--- Then log the response
  3. Click Run Test.

    The color-coded results of the test appear.

    Color-coded results of the test

    As you experiment in the BAT playground, hints appear when errors occur.

    hints appear when errors occur

Next, schedule testing and monitoring.

In this topic: