Makina

Makina is a testing library that provides a domain specific language for writing property-based testing models for stateful programs.

Installation

Makina can be installed by adding this git repository to your list of dependencies in mix.exs:

def deps do
[
{:makina, git: "https://gitlab.com/babel-upm/makina/makina.git", branch: "master"}
]
end

Configuration

In order to make the models1 executable, Makina should be configured with a compatible property-based testing library like PropCheck:

config :makina, checker: PropCheck

Once the project is configured tests and properties can be written and executed using the default mechanisms provided by the property-based library.

You also need to setup the Makina compilation tracer:

def project do
[
elixirc_options: [{:tracers, [Makina.Tracer]}]
]

Writing a basic Makina model

After importing the library and configuring the project you can start writing Makina models. A Makina model must be defined inside an Elixir module. To start writing a Makina model you need to import the DSL using the use macro:

defmodule ModelExample do
use Makina

Once the library is imported you can start defining your model. A model in Makina is composed by two main parts: a state and some commands that interact with that state. Makina provides the macros state and command for this purpose.

Writing the state definition in a Makina model

Only one call to state is allowed in each model. This macro supports the following syntax:

state attribute_name: initial_value :: type,
...

where:

Writing a command in a Makina model

Any number of command definitions is allowed in a Makina model. To write a command Makina provides the command macro. This macro supports the following syntax:

command command_name(argument :: type, ...) :: return_type do
# callbacks
...
end

where:

Inside the command block the user must write the callbacks that specify the behaviour of the model. In command definitions callbacks do not need any arguments, these are automatically inserted during macro expansion. Makina commands allow the definition of the callbacks:

Writing a property

Finally, once the model is written you need to write a property to execute the tests. We rely this work on the property-based testing library of choice2.

Footnotes

1 examples of models can be found here

2 examples of properties using PropCheck can be found here