Heroku provides a CI solution out of the box for teams. They can run tests in dyno instance for your project. What’s more interesting you can run parallel dynos as part of your CI build. This allows you to split tests on parallel dynos to complete CI build faster and save time.

Heroku

Heroku charges you for seconds spent in runtime for each dyno. It means instead of running your slow test suite on a single dyno you could split it across multiple dynos and pay more or less the same and significantly reduce the CI build time for your project.

How to start with Heroku CI

If you or your company has already created a team in Heroku then you can use Heroku CI and run tests for your project there.

In Heroku, you can open your team and particular pipeline for one of your projects. You will find there a Tests tab where you can enable Heroku CI.

You will also need an app.json file in a repository of your project. The file contains information about what’s needed to run the project on Heroku. We will add to the app.json file additional configuration needed for Heroku CI.

In order to use Heroku CI parallel test runs, we need to have it enabled. You will have to ask Heroku support to activate it for your project. This feature allows to run up to 32 parallel dynos for your CI build.

You can also watch all the steps on more detailed video or copy some examples from this article.

Below I will show you examples how to split tests on Heroku CI for Ruby and JavaScript projects.

How to run parallel dynos for test suite in Ruby on Rails project

We can split Ruby tests written in RSpec, Minitest or other tests runners across parallel dynos in a dynamic way where all dynos will finish work at similar time so we will get results about our test suite being green or red as soon as possible. To do it we will use Knapsack Pro tool with its Queue Mode for dynamic test suite split. With quantity key, we can set how many parallel dynos we want to use to run our scripts test command.

{
  "environments": {
    "test": {
      "formation": {
        "test": {
          "quantity": 2
        }
      },
      "addons": [
        "heroku-postgresql"
      ],
      "scripts": {
        "test": "bundle exec rake knapsack_pro:rspec"
      },
      "env": {
        "KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC": "rspec-token"
      }
    }
  }
}

We also can change dyno size for our CI build. If you run complex tests that need more CPU or memory you could add size parameter to app.json to define dyno type.

{
  "environments": {
    "test": {
      "formation": {
        "test": {
          "quantity": 1,
          "size": "performance-l"
        }
      }
   }
}

Run JavaScript tests across parallel Heroku CI dynos for Cypress E2E test suite

End-to-end tests (E2E) often takes a lot of time because clicking through multiple scenarios of your website is time-consuming. Splitting Cypress test suite on multiple dynos will help us save a lot of time and keep CI build fast.

We can use @knapsack-pro/cypress project for that. It uses Knapsack Pro Queue Mode.

Here is a config for your app.json

{
  "environments": {
    "test": {
      "formation": {
        "test": {
          "quantity": 2
        }
      },
      "addons": [
        "heroku-postgresql"
      ],
      "scripts": {
        "test": "$(npm bin)/knapsack-pro-cypress"
      },
      "env": {
        "KNAPSACK_PRO_TEST_SUITE_TOKEN_CYPRESS": "example"
      }
    }
  }
}

If you would like to learn more about Cypress then check the video in an article about running javascript E2E tests with Cypress on parallel CI nodes.

Summary

Heroku CI is a great addition to Heroku. If you already use Heroku you can easily leverage dynos and keep low costs of your CI as you pay only for dyno usage. The great thing is that you can run many parallel CI dynos with a subset of your test suite to save a ton of time for your engineering team. You can learn more about how Knapsack Pro can help you save time with faster CI builds.

If you’d like to compare Heroku CI with other solutions, check out our comparison pages: Heroku CI vs Circle CI, Github Actions vs Heroku CI, Netlify vs Heroku, and Heroku CI vs Other CIs