Skip to content

Run Integration/E2E Tests

Running integration or end-to-end (E2E) tests against an application's deployed environments is crucial for ensuring the quality and reliability of that application. Using GitHub Actions as an example, this guide demonstrates how to use a CI/CD pipeline to set up and run integration tests on Coherence environments.

Overview

The general process for running integration tests on Coherence environments is as follows:

  • You deploy an application to a Coherence environment.
  • If the deployment is successful, it triggers a test workflow, in which Coherence posts a check run (called Coherence deploy for SERVICE_NAME) against each commit that it deploys for a service.
  • You run integration tests against the deployed environment.
  • Your test results are reported.

While this example uses GitHub Actions, you can apply similar principles to other CI/CD providers or test runners.

GitHub Actions example

The following GitHub Actions workflow triggers integration tests after a successful deployment to a Coherence service called web in your environment:

name: Staging Integration Tests

on:
  check_run:
    types:
      - completed

jobs:
  e2e_testing:
    if: ${{ github.event.check_run.name == 'Coherence deploy for web' }}
    uses: ./.github/workflows/run-integration-tests.yml
    secrets: inherit
    with:
      test_search_query: MY_SEARCH_QUERY (e.g. ${{ startsWith(github.ref, 'refs/tags/release') && 'tag:production' || 'tag:staging' }})

The workflow:

  • Is triggered when the check_run event is completed
  • Checks whether the completed check_run is named "Coherence deploy for web" (to confirm that it corresponds to a successful deployment in Coherence)
  • Runs a reusable workflow defined in .github/workflows/run-integration-tests.yml if the condition is met (the name is correct)
  • Sets the test_search_query input based on whether the trigger is a release tag or not (allowing different tests to be run for production and staging environments)

Setting up your test workflow

Your run-integration-tests.yml file should contain the actual test execution steps.

Consider the following YAML as an example:

name: Run E2E Tests

on:
  workflow_call:
    inputs:
      test_search_query:
        required: true
        type: string

jobs:
  run_tests:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Use Node.js
        uses: actions/setup-node@v2
        with:
          node-version: '14'
      - name: Install dependencies
        run: npm ci
      - name: Run E2E tests
        run: npm run test:e2e
        env:
          TEST_URL: ${{ secrets.COHERENCE_ENVIRONMENT_URL }}
          TEST_SEARCH_QUERY: ${{ inputs.test_search_query }}

This workflow:

  • Sets up a Node.js environment
  • Installs dependencies
  • Runs your E2E tests, passing in the Coherence environment URL and the test search query

Coherence integration

Complete the following steps to ensure that your GitHub Actions pipeline works with Coherence:

  • Confirm that your Coherence deployments are set up to create GitHub check runs. Typically, this is automatically configured when you connect your GitHub repository to Coherence.
  • Store your Coherence environment URL as a secret in your GitHub repository settings. Name it COHERENCE_ENVIRONMENT_URL.
  • Add the TEST_URL environment variable to your test code. Use it to know which URL to test against.

Best practices

  • Parameterize your tests: Use environment variables or configuration files to make your tests flexible enough to run against different environments.
  • Use test tagging: Implement a tagging system in your tests to run subsets of tests easily for different environments or scenarios.
  • Handle authentication: If your app requires authentication, consider setting up test users or implementing a way to generate authentication tokens for your tests.
  • Clean up test data: Prevent test pollution in shared environments by ensuring your tests clean up any data they create.
  • Parallel testing: For large test suites, consider running tests in parallel to speed up the testing process.

Conclusion

By incorporating integration tests in your CI/CD pipeline or workflow for Coherence deployments, you can ensure that every successful deployment is immediately verified. This allows you to catch issues early and feel confident in the quality of your deployments.

Remember to adjust the example workflows and code to fit your specific project structure and testing framework.