Muex (Muex v0.6.0)

View Source

Muex - 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

Usage

Run mutation testing via Mix task:

mix muex

With options:

mix muex --files "lib/**/*.ex" --mutators arithmetic,comparison --fail-at 80

Creating 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$/
end

Creating 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

run(config)

@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.