For our api tests, we use Postman to make requests and assert the responses.
A few services must be running and accessible before the api tests can be run;
- The target
lang/frameworkapi must be running and accessible on port 8080 (this is the api you want to test). - The expectations api must be running and accessible on port 3000.
You can choose to run the api tests with docker or directly within Postman itself.
This method uses the development environment as opposed to the Api Testing environment. This is because the Api Testing env uses Docker service names which are used to identify containers on the same network.
- Download and install Postman (download link here).
- Import Development environment and collection. These can be located at
postman/Development.api_farm.jsonandpostman/API_farm.postman_collection.jsonrespectively.
- Ensure the Development environment is selected within Postman.
- Check that your workspace includes the Samples & Tests (yours might not look exactly like the image below due to updates made).
- Highlight the Tests folder and click Run, this will open the Postman Test Runner.
- Finally, hit
Run API_farmto fire off the tests. Provided services are available and you're using master, you should have results similar to those below;
This method is used for the CI pipeline.
- Download and install Docker (download link here)
- From this directory, run the
run.shscript. It requires the api container name you wish to run the tests against (e.g;ruby_sinatrafor ruby/sinatra).
./run.sh ruby_sinatra- Results from the tests should be output to the console. As well as a final indication as to whether all the tests passed;
Logs are captured from api tests run using Docker. These can be found within the relative directory ./logs.