Skip to content

Elixir adapter for Buildkite Test Analytics which uses an ExUnit formatter to connect information about your tests

License

Notifications You must be signed in to change notification settings

buildkite/test_collector_elixir

Repository files navigation

Buildkite Test Collector for Elixir (Beta)

The official Elixir adapter for Buildkite Test Analytics which uses an ExUnit formatter to connect information about your tests.

Supported test frameworks: ExUnit. 📦 Supported CI systems: Buildkite, GitHub Actions, CircleCI, and others via the BUILDKITE_ANALYTICS_* environment variables.

👉 Installing

  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.0", only: [:test]}
  ]
end
  1. Set up your API token

In your config/test.exs (or other environment configuration as appropriate) add the analytics API token. We suggest that you retrieve the token from the environment, and configure your CI environment accordingly (eg via secrets).

import Config


config :buildkite_test_collector,
  api_key: System.get_env("BUILDKITE_ANALYTICS_TOKEN")
  1. Add BuildkiteTestCollectorFormatter to your ExUnit configuration in test/test_helper.exs:
ExUnit.configure formatters: [BuildkiteTestCollector.Formatter, ExUnit.CLIFormatter]
ExUnit.start
  1. Run your tests

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
  1. Verify that it works

If all is well, you should see the test run in the test analytics section of the Buildkite dashboard.

🎢 Tracing

Buildkite Test Analytics has support for tracing potentially slow operations within your tests (SQL queries, HTTP requests, etc). Because ExUnit can run multiple tests simultaneously, it is difficult to achieve this without requiring code changes - we cannot simply use telemetry events because we cannot easily attribute the events to specific tests across process boundaries. Instead we have provided a simple API to manually instrument operations within your tests.

🔜 Roadmap

See the GitHub 'enhancement' issues for planned features. Pull requests are always welcome, and we’ll give you feedback and guidance if you choose to contribute 💚

⚒ Developing

After cloning the repository, install the dependencies:

mix deps.get

And run the tests:

mix test

Useful resources for developing collectors include the Buildkite Test Analytics docs and the RSpec and Minitest collectors.

👩‍💻 Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/buildkite/test_collector_elixir

Please use Conventional Commits so that the changelog and version can be automatically tracked via the git_ops package.

🚀 Releasing

Important: some of this process is already automated by Github Actions. It should be completely automated shortly.

# Generate the new version and changelog
mix git_ops.release

# Push the tags
git push && git push --tags

# Publish the Hex package
mix hex.publish

# Create a new GitHub release
open "https://github.com/buildkite/test_collector_elixir/releases"

📜 License

The package is available as open source under the terms of the MIT License.

🤙 Thanks

Thanks to the folks at Alembic for building and maintaining this package.

About

Elixir adapter for Buildkite Test Analytics which uses an ExUnit formatter to connect information about your tests

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages