Compile and test erlang sources in an application

Doing TDD or test driven development with the maven-erlang-plugin is easy. Put source modules and tests in the respective diretories. For example in an erlang-std project we have the following modules and tests:


While in an erlang-otp project, we would expect the files in the following layout:


A simple test for our module.erl is defined in the file module_tests.erl and contains:


one_success_test() ->
    ?assertMatch(2, module:one(1)).

one_failing_test() ->
    ?assertMatch(not_ok, module:one(ok)).

So we'll implement a trivial module.erl like this:


one(Arg) when is_integer(Arg) ->
    Arg + 1;
one(Arg) ->

Compiling and testing is simply done with:

Tests fail.

Oh, a test fails since we've made a wrong expectation. The output should be the same as the input. Let's fix that and run the tests again.

Tests ok.

The created output files from compile and test can be found in the target directory:

target/app-1.0-test/ebin/cover2.beam           # plugin internals (not packaged)
target/app-1.0-test/ebin/cover2.erl            # plugin internals (not packaged)
target/app-1.0-test/ebin/module.beam           # (not packaged)
target/app-1.0-test/ebin/module_tests.beam     # (not packaged)
target/app-1.0-test/ebin/surefire.beam         # plugin internals (not packaged)
target/app-1.0-test/ebin/surefire.erl          # plugin internals (not packaged)
target/app-1.0-test/ebin/ttycapture.beam       # plugin internals (not packaged)
target/app-1.0-test/ebin/ttycapture.erl        # plugin internals (not packaged)
target/surefire-reports/TEST-module_tests.xml  # plugin internals (not packaged)