Automated Testing with CircleCi - Jacob1225/pufferfish-minecraft-mod GitHub Wiki

The major benefits of testing are felt when they run in an automated environment that can identify bugs before damaging code changes are merged. In this project, CircleCi and github have been linked to protect key branches from damaging code.

Github Status Checks & CircleCi Workflows

Github has a very useful feature called status checks, which can be added into branch protection rules. In fact, these status checks are directly related to CircleCi workflows, which are automated tasks that run within the CircleCi environment and return a pass or fail status.

Configuring workflows in CircleCi

  • Workflows can be created within the config.yml file.

View current workflows in config.yml:

image

image

  • Our project’s config has two jobs, where the test job is displayed above.
  • Each job executes a specific command. The test job above, finds the cached gradle dependencies and runs all the tests for the project.
  • The config names the workflow build_and_test, which runs two jobs: build and test.
  • The status of each job can be seen by clicking on the specific job from the CircleCi dashboard

View of CircleCi Jobs:

image

Github Branch Protection Rules:

To make use of the CircleCi workflows in an automated fashion, our team has set up branch protection rules to execute these jobs when code is committed to github.

  • If all jobs return a successful status the commit is given a checkmark in github.
  • If any of the jobs fail, the commit will be marked with a red ‘X’.
  • Failing commits cannot be merged to the protected branch.

View of branch protection rule in github:

image

  • The above image protects the testing/integration-tests branch.
  • Our rules involve requiring that pull requests be made and approved by at least 1 member before merging any code to this branch.
  • Also, this branch requires that the CircleCi test job returns a successful status before merging any code.

How Do All the Pieces Fit Together?

  1. We first link our github repository to CircleCi.
  2. We create our config.yml file with the jobs and workflows to execute.
  3. CircleCi runs each job on every code commit.
  4. We add github branch protection rules to specific branches (in our case main).
  5. We specify which CircleCi job must succeed in order to merge code into the protected branch.
  6. The pieces are now all connected and provide automated testing!