knowledge-kitchen

Continuous Integration - Automated Software Testing

Automatically run unit tests.

  1. Overview
  2. Typical Workflow
  3. Best Practices
  4. Software as a Service
  5. Circle CI
  6. GitHub Actions
  7. Conclusions

Overview

Concept

As developers work on a project, they make changes.

Benefits

Automated Continuous Integration has several benefits:

Typical Workflow

Overview

Continuous Integration process diagram

Version Control

When a developer makes changes to a system, they typically check those changes into a version control system.

Build System

Once a change to the version control repository has been detected, the Continous Integration server will automatically trigger a new build to begin in order to be able to test the system once the build is done.

Testing Framework

Once a fresh build is complete, the testing framework will run automated tests on the system.

Notifications

Developers are notified, immediately upon completion of the build and test phases, whether each of the steps succeeded or failed.

With most Continuous Integration tools, notifications can be sent via

Badges

In popular project management tools such as GitHub, badges automatically posted to a repository’s README.md can indicate the last known success or failure of the build and tests for all to see.

Continuous Integration badges

Best Practices

Commit small changes

Committing small changes to version control limits the scope of what has changed so failures in building or testing are more quickly identified and remedied.

You break it, you fix it!

If a given developer has broken the build, it is their responsibility to fix it.

Test the right stuff

It’s common to miss obvious bugs because automated unit and integration tests have poor code coverage or test the wrong things.

What to produce

Plan on producing a status, a log, and an artefact.

Software as a Service

Continuous Deployment

An extension of Continuous Integration is Continuous Deployment (CD)…

CI/CD Automation pipelines

Continuous Integration (CI), followed by Continuous Deployment (CD) goes hand-in-hand with Software as a Service (SaaS).

Circle CI

Hosted continuous integration service

Circle CI is a proprietary hosted Continuous Integration web service with a free tier of service that is suitable for small projects.

Virtual build servers

When a change is detected in version control, Circle CI boots up a new virtual server.

Key features

Circle CI comes with the common features of any continuous integration server.

Basic configuration

Circle CI’s build and test configuration is written in YAML (YAML Ain’t Markup Language) and saved into a file named config.yml in a .circleci directory of your project.

GitHub integration

To link Circle CI to a GitHub repository, such that it detects changes to the repository and triggers continuous integration builds and testing, go to circleci.com.

Highly configurable

Circle CI supports detailed instructions and can run arbitrary code at various lifecycle points in the build.

Messenger integration

Circle CI can send notifications to Discord, Slack, MS Teams or other messenger apps indicating the results of the latest build.

Badges

You can embed build status badges that Circle CI will use to automatically show the latest status of your build into your project’s README.md.

[![CircleCI](https://circleci.com/gh/software-assignments-spring2022/your-repo-name-here/tree/master.svg?style=shield)](https://circleci.com/gh/software-assignments-spring2022/your-repo-name-here/tree/master)

Warnings Cause Build Failure

By default, both errors and warnings produced by a project will cause the continuous integration server to fail the build.

GitHub Actions

Overview

Like other continuous integration services, GitHub Actions is a hosted service that runs automated builds, tests, and other processes on a virtual machine.

Virtual build servers

When a change is detected in version control (whether a push, pull request, merge, or other), GitHub Actions boots up a new virtual server.

Key features

GitHub Actions comes with the common features of any continuous integration server.

GitHub integration

As a part of a GitHub repository, GitHub Actions does not need any special setup in order to detects change to the repository and trigger continuous integration builds and testing.

Basic configuration

Configuration files, known as “workflows”, are written in YAML (YAML Ain’t Markup Language).

Highly configurable

GitHub Actions supports detailed instructions and can run arbitrary code at various lifecycle points in the build.

Example

A Python build/test workflow that runs on every pull request. Linting using pylint or other code linter could easily be added.

on: [pull_request]
jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ["3.6", "3.8", "3.10"]
    steps:
      - uses: actions/checkout@v3
      - name: Set up Python $
        uses: actions/setup-python@v4
        with:
          python-version: $
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install pytest
          if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
      - name: Test with pytest
        run: |
          pytest

Badges

You can embed build/test status badges that GitHub Actions will use to automatically show the latest status of your build into your project’s README.md.

![Your custom badge name](https://github.com/<OWNER>/<REPOSITORY>/actions/workflows/<WORKFLOW_FILE>/badge.svg)

Messenger integration

GitHub Actions can send notifications to Discord, Slack, MS Teams or other messenger apps indicating the results of the latest build.

Warnings Cause Build Failure

By default, both errors and warnings produced by a project will cause the continuous integration server to fail the build.

Conclusions

Thank you. Bye.