Muex (Muex v0.6.0)
View SourceMuex - Mutation testing library for Elixir, Erlang, and other languages.
Muex provides a language-agnostic mutation testing framework with dependency injection for language adapters, making it easy to extend support to new languages.
Architecture
Muex.Language- Behaviour for language adapters (parse, unparse, compile)Muex.Mutator- Behaviour for mutation strategiesMuex.Loader- Discovers and loads source filesMuex.Compiler- Compiles mutated code and manages hot-swappingMuex.Runner- Executes tests against mutantsMuex.Reporter- Reports mutation testing results
Usage
Run mutation testing via Mix task:
mix muexWith options:
mix muex --files "lib/**/*.ex" --mutators arithmetic,comparison --fail-at 80Creating a Language Adapter
To add support for a new language, implement the Muex.Language behaviour:
defmodule Muex.Language.MyLanguage do
@behaviour Muex.Language
@impl true
def parse(source), do: {:ok, parse_to_ast(source)}
@impl true
def unparse(ast), do: {:ok, ast_to_string(ast)}
@impl true
def compile(source, module_name), do: {:ok, compiled_module}
@impl true
def file_extensions, do: [".mylang"]
@impl true
def test_file_pattern, do: ~r/_test.mylang$/
endCreating a Mutator
To add a new mutation strategy, implement the Muex.Mutator behaviour:
defmodule Muex.Mutator.MyMutator do
@behaviour Muex.Mutator
@impl true
def mutate(ast, context) do
# Return list of mutations
[]
end
@impl true
def name, do: "MyMutator"
@impl true
def description, do: "Custom mutation strategy"
end
Summary
Functions
Executes the full mutation testing pipeline from a %Muex.Config{}.
Functions
@spec run(Muex.Config.t()) :: {:ok, map()} | {:error, String.t()}
Executes the full mutation testing pipeline from a %Muex.Config{}.
Returns {:ok, %{results: results, score: mutation_score}} on success
or {:error, reason} on failure. Never calls Mix.raise or System.halt;
the caller decides how to handle the outcome.