An ExUnit formatter that outputs a series of JSON objects.
Inspired and designed to be compatible with mocha-json-streamier-reporter
If available in Hex, the package can be installed
by adding exunit_json_formatter to your list of dependencies in mix.exs:
def deps do
[{:exunit_json_formatter, "~> 0.1.0"}]
endConfigure the formatter in test/test_helper.exs:
ExUnit.start(formatters: [ExUnitJsonFormatter])There are multiple ways to configure file output:
ExUnit.start(formatters: [{ExUnitJsonFormatter, output_file: "test-results.json"}])EXUNIT_JSON_OUTPUT_FILE=test-results.json mix test --formatter ExUnitJsonFormatteror
export EXUNIT_JSON_OUTPUT_FILE=test-results.json
mix test --formatter ExUnitJsonFormatterdef project do
[
# ...
test_coverage: [
tool: ExUnitJsonFormatter,
output_file: "test-results.json"
]
]
endNote: Options specified in test_helper.exs take precedence over environment variables.
File output is useful when you need clean JSON output separate from test logs and other CLI output.
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/exunit_json_formatter.