Run Service Test Locally
So far, you have created a collection with the necessary test requests. Now we will convert the collection into a test suite, and run the test suite against the service running locally in the developer's laptop using auto-created mocks for the producer services.
Convert collection to test suite
- In API Studio, go to the API catalog. From the API catalog, select Collection from the Source dropdown, and then select the collection created earlier.
- Click on Save as test suite to convert the collection to a test suite. The default name assigned to the test suite created from the collection movieinfo_service_test will be GL_movieinfo_service_test.
Run test locally
Service testing locally requires the following steps:
- Creating a test suite including mocks for egress requests
- Service under test running locally
- Forwarding the test requests from the cloud test driver to the service running locally
- Setting up the decision rules to determine if the tests are successful
Mesh Dynamics uses a cloud-based test driver to send the test requests to the target. To run the test locally, you have to use a product like ngrok to generate a secure URL to your localhost server through any firewall. This provides the test driver an endpoint to send the test requests to.
- In the API editor, change the egress request configuration to use mock services for all egress requests.
- In API Studio, go to the Test Runner screen.
- Let us assume that you do not have a pre-defined configuration for the service test. From the Select Test Config dropdown, select Other.
- When the Test Config is set to Other, we assume that you will specify the endpoint. So we set the Test Instance to Other by default. Change it to use one of the predefined instances if necessary.
- Next we need to get an endpoint that the cloud test driver can send the requests to. Generate a secure endpoint using ngrok. We need to specify the port on localhost. In this example, the Eclipse IDE is configured to listen to port 8080.
> ngrok http 8080
- In API Studio, configure the endpoint for the service test using the endpoint url from ngrok.
- In this example, we are assuming that there are no listeners deployed in the setup. All the API requests are only visible to the API Studio proxy. Select the Store to Datastore checkbox to save the API execution data to the Mesh Dynamics data store.
- Select the test suite: GL_movieinfo_service_test
- Select the service to test from the Select Service dropdown.
- Start the test by clicking the Run Test button.
- When the test finishes, the results will be available in the results section.
Note that for the first run, the pass/fail decisions are made based on default settings for the decision rules. After the first run, you can go in and update the decision rules to reflect your business needs.
Next, we will configure the service test to run in your test environment instead of locally. The tests can be initiated either from CI or from the API Studio UI.