Skip to content

elixir_test

Runs ExUnit tests against an elixir_library already compiled with mix_env = "test".

Description

elixir_test depends on exactly one elixir_library target. The library must compile with mix_env = "test". During the test action, Once creates a test layout with symlinks to the compiled library and dependency bytecode, then runs the tests without recompiling the application.

That split lets a changed test file rerun tests without recompiling the application. A changed library source invalidates both the compiled library and the dependent test result. By default, tests run through direct ExUnit with elixir, so a package does not need mix.exs. Set mix_config when a target should run through mix test --no-compile --no-deps-check instead. Library bytecode must already be built by Once in both modes.

Attributes

AttributeTypeRequiredDefaultDescription
mix_configstringnoemptyOptional package-relative Mix project file. When omitted, tests run through direct ExUnit without requiring a Mix project
configlist<string>no["config/**/*.exs"]Config file globs included in the test action key
config_fileslist<string>no[]Buck-compatible alias for additional config file globs
datalist<string>no[]Data file globs available during tests
os_envmap<string, string>no{}Buck-compatible environment variables exported before running tests
env_inheritlist<string>no[]Host environment variable names inherited before explicit env values
envmap<string, string>no{}Environment variables exported before running tests
test_argslist<string>no[]Additional arguments appended to the test runner
elixir_optslist<string>no[]Bazel-compatible options passed to the direct Elixir interpreter before test files
setupstringnoemptyShell snippet run after the test environment is prepared and before ExUnit starts
no_startboolnofalsePass --no-start to mix test when mix_config enables Mix mode
ez_depslist<string>no[]Reserved archive dependencies
toolslist<string>no[]Package-relative executable or support-file globs available to the test setup command
labelslist<string>no[]Labels exposed through once_test_info
timeout_msintnoemptyOptional test timeout in milliseconds

A non-empty ez_deps value fails validation because Once cannot place Erlang archives on the ExUnit code path.

elixir_opts applies only to direct ExUnit mode. When mix_config selects Mix mode, use test_args; combining Mix mode with elixir_opts fails validation.

Dependency Edges

EdgeAcceptsDescription
depselixir_appThe test-environment Elixir application under test

Providers

The target emits once_test_info.

Capabilities

CapabilityOutput groups
testdefault, test_results, logs

Example

toml
[[target]]
name = "greeting"
kind = "elixir_library"
srcs = ["lib/**/*.ex"]

[target.attrs]
app_name = "greeting"
mix_env = "test"

[[target]]
name = "greeting_test"
kind = "elixir_test"
srcs = ["test/**/*_test.exs"]
deps = ["./greeting"]

[target.attrs]
labels = ["unit"]

Released under an open-source license.