-
Notifications
You must be signed in to change notification settings - Fork 108
Integration Tests
Integration tests are a critical part of ensuring software quality. This page includes patterns and best practices for integration testing this application.
Cucumber is a tool that enables behavior-driven development (BDD). This application uses it to define and execute acceptance level integration tests of the backend service. BDD involves translating end user requirements into test scenarios written in plain english that all stakeholders can understand, review, and agree upon before a feature is implemented. Here is an example of a test scenario in Cucumber:
Scenario: User creates an application
When a user creates an application
Then a new application should be created
Once the feature is implemented, Cucumber provides tooling to map each line of the above scenario to code that performs the actions described in the scenario against an actual running instance of the service. This allows the scenarios to not only define the expected behavior, but it also becomes an executable test that verifies the application meets those expectations. These tests are run automatically as part of a CD pipeline so the expected behavior continues to be verified with every change made to the system.
To learn more about BDD, why it works, and common pitfalls to watch out for, read this blog post.
Examples in this project:
- Example of feature scenarios describing expected CreateApplication API behavior.
- Each line of the feature scenarios are mapped to code that execute that step. For example, this scenario line is mapped by Cucumber to this method, which executes the step against the service.
The static website component of this application is tested using Nightwatch.js, a popular framework for end-to-end testing web applications. Nightwatch.js allows you to define friendly names for elements of each page of your application and then define specs which are test scenarios to interact with the page and verify it behaves as expected. These tests are run as part of the CD pipeline by AWS CodeBuild. The AWS CodeBuild image comes out of the box with web driver support for testing Chrome and Firefox browsers.
Examples in this project:
- The CD pipeline is configured to point CodeBuild to run the integration tests using the buildspec-integ-test.yaml definition. An instance of the backend and website are built and deployed specifically for the integration test run. Environment variables are set to pass the website URL and Cognito user pool id to the integration tests. Then the tests are run using the Chrome and Firefox web drivers. Nightwatch configuration for Chrome and Firefox web drivers can be found here.
- The tests create a test user in the backend's Cognito user pool for use throughout the tests. The test user is signed in before executing each test scenario. The tests then verify different scenario on the website such as creating an application.