Contact Us 1-800-596-4880

Recording a Test from an Exchange Example

The following example shows you how to import to Anypoint Studio an existing project from Anypoint Exchange and then record the flow processing to create a unit test for the flows.

Prerequisite

Testing the Login Form Using the HTTP Connector Example

  1. Click the Open Exchange icon 3%.

  2. Select Provided by MuleSoft in the pop-up Exchange window, filter per Examples, and look for the Login Form Using the HTTP Connector.

  3. Click Open.
    Studio imports the example as a new working project.

  4. If prompted, select Perform Update in Update your Workspace.

  5. Select the Manage Mule Projects APIs icon 2%.

  6. Select Modules and update both MUnit and Munit Tools:

    update munit
  7. Select Apply and Close.

Testing the Process for a Successful Login Attempt

  1. In your project, right-click DoLoginFlow and select Munit > Record new test for this flow:

    login flow test recorder example

    The test recorder starts your project and starts recording the event going through that flow.

  2. Open a browser and navigate to http://0.0.0.0:8081/login.

  3. Type mule for both Username and Password, and click Submit.

    The test recorder captures this event and stops the recording.

  4. Return to Studio and click Configure Test:

    stops recording
  5. Select the file name for the MUnit test suite in which you want to record your test.

  6. Under Test name, type DoLoginFlow-successfull.

  7. Set the test recorder to set the recorded input of the flow, and assert that the recorded output is the expected output by the test.

  8. In Successful login, select Verify that this process was called and set the counter equal to to 1 time.

  9. Click Next and then Finish.

    A fully functional MUnit test is generated to assert that the process in your application works as expected when the login is successful.

Testing the Process for an Unsuccessful Login Attempt

  1. In your project, right-click DoLoginFlow and select Munit > Record new test for this flow:

    login flow test recorder example

    The test recorder starts your project and starts recording the event going through that flow.

  2. Open a browser and navigate to http://0.0.0.0:8081/login.

  3. Type admin in both Username and Password, and click Submit:

    The test recorder captures this event and stops the recording.

  4. Return to Studio and click Configure Test:

    stops recording
  5. Select the file name for the MUnit test suite in which you want to record your test.

  6. Under Test name, type DoLoginFlow-unsuccessfull.

  7. Set the test recorder to set the recorded input of the flow, and assert that the recorded output is the expected output by the test.

  8. In the Unsuccessful login parse template step, select Verify that this process was called and set the counter to equal to 1 time.

  9. Click Next and then Finish.

    A fully functional MUnit test is generated to assert that the process in your application works as expected when the login fails.