Skip to content

Testing

Jon Freer edited this page Oct 20, 2018 · 1 revision

Unit Tests

Unit testing is implemented using JUnit. To execute the unit tests, run the following command in the project's root directory:

mvn test

If your unit tests don't seem to be executing, ensure that your tests follow the naming convention enforced by the Maven Surefire plugin!

Coverage & Code Analysis

We use SonarCloud to calculate unit test code coverage, as well as additional metrics related to code quality. The SonarCloud platform provides a deep level of code analysis that identifies potential bugs, code smells, and technical debt, which allows us to keep a pulse on our code quality.

Postman Tests

Postman is a popular testing and debugging application for HTTP APIs. On top of making use of the graphical user interface during our development workflows, we make use of it's command line collection runner application, called newman, for acceptance testing.

The tests themselves are created using the Postman UI in the form of request collections. The request collections are exported in JSON format, and stored in a file named noti_tests.postman_collection.json within the /src/test/resources folder. In addition, the Postman environment variables used to resolved variables within the exported collections are also exported and stored in a file named noti_local.postman_environment.json located in the same folder.

The primary goal of these tests is to perform a particular subset of acceptance tests that are focused on validating HTTP protocol interactions. These tests ultimately validate that the correct HTTP headers and status codes are communicated, and that protocol support for various actions such as conditional requests, content negotiation, etc. operate correctly.

Continuous Integration

For continuous integration (CI), we use Travis CI. Each time there is a pull request into the master branch, Travis CI kicks off two builds: one testing the feature branch in isolation, and the other testing the merge commit. In addition, Travis CI will initiate a build each time a pull request is accepted into master. Our Travis CI build configuration is defined in a file named .travis.yml within the root directory of the project.

Build Stages

Currently, each Travis CI build consists of two build stages:

  1. Unit test
  2. Postman test

Within the Unit test stage, both unit tests and code analysis are executed. In the Postman test stage, all Postman request collections defined in noti_tests.postman_collection.json are executed using newman.

These stages are executed sequentially, and failure of either one prevents the build from passing.

Clone this wiki locally