Elixir collectors

To use Buildkite Test Engine with your Elixir projects, use :github: test_collector_elixir with ExUnit.

Recommended setup

The recommended way to set up a new test suite is to add the Tests Buildkite plugin to the step that runs your tests. It works with every runner that bktec supports, and the entire setup is configuration-only — you can get a test suite running through changes to pipeline.yml alone, with no modifications to your application code.

Use the language-specific test collector documented on this page when you want deeper framework integration — such as custom execution tags, span annotations, or richer per-framework data. Language-specific collectors still pair well with the Tests Buildkite plugin, but adding one requires changes to your application code.

You can also upload test results by importing JSON or JUnit XML.

ExUnit

ExUnit is a Elixir unit test library.

Before you start, make sure ExUnit runs with access to CI environment variables.

  1. Create a test suite and copy the API token that it gives you.

  2. Add buildkite_test_collector to your list of dependencies in mix.exs:

    def deps do
      [
        {:buildkite_test_collector, "~> 0.3.1", only: [:test]}
      ]
    end
    
  3. Set up your API token:

    In your config/test.exs (or other environment configuration as appropriate) add the Buildkite Test Engine API token. We suggest that you retrieve the token from the environment, and configure your CI environment accordingly (for example using secrets).

    import Config
    
    config :buildkite_test_collector,
      api_key: System.get_env("BUILDKITE_ANALYTICS_TOKEN")
    
  4. Add BuildkiteTestCollectorFormatter to your ExUnit configuration in test/test_helper.exs:

    ExUnit.configure formatters: [BuildkiteTestCollector.Formatter, ExUnit.CLIFormatter]
    ExUnit.start
    
  5. Run your tests like normal:

    Note that we attempt to detect the presence of several common CI environments. However if this fails you can set the CI environment variable to any value and it will work.

    $ mix test
    
    ...
    
    Finished in 0.01 seconds (0.003s on load, 0.004s on tests)
    3 tests, 0 failures
    
    Randomized with seed 12345
    
  6. Verify that it works. If all is well, you should see the test run analytics on the Buildkite Test Engine dashboard.