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
-
Your Anypoint Platform credentials are configured in Studio.
See Configuring Anypoint Platform Credentials for more information.
Testing the Login Form Using the HTTP Connector Example
-
Click the Open Exchange icon .
-
Select Provided by MuleSoft in the pop-up Exchange window, filter per Examples, and look for the Login Form Using the HTTP Connector.
-
Click Open.
Studio imports the example as a new working project. -
If prompted, select Perform Update in Update your Workspace.
-
Select the Manage Mule Projects APIs icon .
-
Select Modules and update both MUnit and Munit Tools:
-
Select Apply and Close.
Testing the Process for a Successful Login Attempt
-
In your project, right-click
DoLoginFlow
and select Munit > Record new test for this flow:The test recorder starts your project and starts recording the event going through that flow.
-
Open a browser and navigate to
http://0.0.0.0:8081/login
. -
Type
mule
for both Username and Password, and click Submit.The test recorder captures this event and stops the recording.
-
Return to Studio and click Configure Test:
-
Select the file name for the MUnit test suite in which you want to record your test.
-
Under Test name, type
DoLoginFlow-successfull
. -
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.
-
In Successful login, select Verify that this process was called and set the counter equal to to
1
time. -
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
-
In your project, right-click
DoLoginFlow
and select Munit > Record new test for this flow:The test recorder starts your project and starts recording the event going through that flow.
-
Open a browser and navigate to
http://0.0.0.0:8081/login
. -
Type
admin
in both Username and Password, and click Submit:The test recorder captures this event and stops the recording.
-
Return to Studio and click Configure Test:
-
Select the file name for the MUnit test suite in which you want to record your test.
-
Under Test name, type
DoLoginFlow-unsuccessfull
. -
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.
-
In the Unsuccessful login parse template step, select Verify that this process was called and set the counter to equal to
1
time. -
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.