Testing

This page will help you in getting started with testing your applications.

Unit Tests

The goal of unit testing is to break your application into the smallest testable units, and test them individually, isolating a specific piece of functionality and ensuring it is working correctly. It is always a good idea to write more unit test cases and relatively fewer component and integration tests. If you want to get an idea of how many tests you should have in different types of testing phases (Unit/Component/Integration), refer this blog

Unit testing simple scala/java classes or objects is straight forward. You can mock external dependencies using Mockito. Refer to the Mockito section for more details.

The following links provide guides for testing applications using different modules of Akka:

Multi-JVM Tests

Testing asynchronous distributed systems requires special tooling/framework support. Sbt has a plugin called sbt-multi-jvm which helps to test systems across multiple JVMs or machines. This is especially useful for integration testing where multiple systems communicate with each other.

You can find more details on multi-JVM tests here.

You can also refer csw for writing your own multi-JVM tests. For example: CommandServiceTest.scala

In case you want to run your multi-JVM tests across machines, refer this multi-node testing guide here.

Mockito

Mocks are used so that unit tests can be written independent of dependencies.
csw uses Mockito for writing unit tests. ScalaTest comes with MockitoSugar trait which provides some basic syntax sugar for Mockito.

For example: ContainerBehaviorTest.scala

Acceptance Tests

This section explains how and where csw maintains and executes acceptance tests. If you are a component writer and want to maintain acceptance tests, you can create a repo similar to csw-acceptance and update dependencies, projects as per your need.

As required by TMT Systems Engineering, the acceptance pipeline runs all the existing Java and Scala tests from csw repo on published bintray binaries rather than directly on source code.

More information can be found here.

Below are the two separate Jenkins pipelines to run csw acceptance tests:

  1. Acceptance Dev Pipeline

    • Automatically triggered every night to get fast feedback and intended for developer’s visibility.
  2. Acceptance Release Pipeline

    • Automatically triggered on completion of csw-prod-release pipeline.
    • csw-prod-release pipeline published CSW artifacts to bintray, and must be manually triggered by an administrator.
Note

csw-prod-release pipeline is responsible for following tasks:

  • build and run csw tests
  • publish binaries to bintray
  • publish paradox documentation
  • publish apps and release notes to github releases
  • trigger acceptance-release pipeline

Acceptance pipelines can also be triggered manually via an HTTP end point, for STIL acceptance tesing, for example. Using the security token obtained from the Jenkins pipeline settings (available upon request), run the curl cmd as shown below:

curl -G 'http://ec2-35-154-215-191.ap-south-1.compute.amazonaws.com:8080/job/acceptance-dev/buildWithParameters'  \
    --data-urlencode token=$DEV_TOKEN \
    --data-urlencode DEV_VERSION=0.1-SNAPSHOT \
    --data-urlencode BUILD_ENV=DEV
  • For triggering acceptance-release pipeline, run below: (Modify parameters as applicable)
curl -G '$REMOTE_JENKINS_URL/job/$JOB_NAME/buildWithParameters' \
    --data-urlencode token=$RELEASE_TOKEN \
    --data-urlencode RELEASE_VERSION=$RELEASE_VERSION \
    --data-urlencode BUILD_ENV=PROD