View Source Criterion (Criterion v0.1.9)

A frame work to write unit tests as a list of steps. It can be used to write tests BDD style.

Usage

  1. Define a feature using feature/2 macro
  2. Define scenarios under the feature using the scenario/3 macro.
  3. Inside each scenario, define steps using the step/3 macro.
  4. Steps can be either plain steps, steps with context variables or shared step
  5. Shared steps can be defined using defstep/4 macro

Example

Shared steps

defmodule Criterion.SharedSteps do
  import Criterion

  defstep "Given a number", _context, args do
    min = args[:min] || 0
    %{number: min + :rand.uniform(100)}
  end
end

Test

defmodule CriterionTest do
  use ExUnit.Case
  import Criterion
  alias Criterion.SharedSteps

  feature "Math" do
    scenario "Square" do
      step "Given a number", from: SharedSteps, where: [min: 2]

      step "When the number is multiplied by it self", %{number: number} do
        result = number * number
        %{result: result}
      end

      step "Then the result is greater than the number", %{result: result, number: number} do
        assert result > number
      end
    end
  end
end

Summary

Functions

Link to this macro

defstep(description, step_var, where_var, list)

View Source (macro)
Link to this macro

feature(description, list)

View Source (macro)
Link to this macro

scenario(description, test_vars \\ Macro.escape(%{}), list)

View Source (macro)