diff options
author | Loïc Hoguin <[email protected]> | 2015-12-24 14:16:38 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2015-12-24 14:16:38 +0100 |
commit | 0dc7f776c59f2a84acd752b590342757c0f6a39a (patch) | |
tree | 3ee200d9826c9c70cfce46e005e3618a59ca004c /guide/ch15.html | |
parent | 33728ad57de0799c32cad1dc3ce642e6b2476d79 (diff) | |
download | erlang.mk-0dc7f776c59f2a84acd752b590342757c0f6a39a.tar.gz erlang.mk-0dc7f776c59f2a84acd752b590342757c0f6a39a.tar.bz2 erlang.mk-0dc7f776c59f2a84acd752b590342757c0f6a39a.zip |
Update user guide
Diffstat (limited to 'guide/ch15.html')
-rw-r--r-- | guide/ch15.html | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/guide/ch15.html b/guide/ch15.html index 3f23d71..bc86d71 100644 --- a/guide/ch15.html +++ b/guide/ch15.html @@ -31,7 +31,43 @@ div.navfooter{margin-bottom:1em} </header> <main> -<div class="navheader"><table width="100%" summary="Navigation header"><tr><td width="20%" align="left"><a accesskey="p" href="ch14.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="ch16.html">Next</a></td></tr></table><hr /></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a id="_eunit"></a>Chapter 15. EUnit</h2></div></div></div><p>Placeholder chapter.</p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch14.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="pt03.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch16.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> </td></tr></table></div> +<div class="navheader"><table width="100%" summary="Navigation header"><tr><td width="20%" align="left"><a accesskey="p" href="ch14.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="ch16.html">Next</a></td></tr></table><hr /></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a id="_eunit"></a>Chapter 15. EUnit</h2></div></div></div><p>EUnit is the tool of choice for unit testing. Erlang.mk +automates a few things on top of EUnit, including the +discovery and running of unit tests.</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_writing_tests"></a>15.1. Writing tests</h2></div></div></div><p>The <a class="ulink" href="http://www.erlang.org/doc/apps/eunit/chapter.html" target="_top">EUnit user guide</a> +is the best place to learn how to write tests. Of note is +that all functions ending with <code class="literal">_test</code> or <code class="literal">_test_</code> will be +picked up as EUnit test cases.</p><p>Erlang.mk will automatically pick up tests found in any of +the Erlang modules of your application. It will also pick up +tests located in the <span class="emphasis"><em>$(TEST_DIR)</em></span> directory, which defaults +to <span class="emphasis"><em>test/</em></span>.</p><p>It is generally a good practice to hide test code from +the code you ship to production. With Erlang.mk, you can +do this thanks to the <code class="literal">TEST</code> macro. It is only defined +when running tests:</p><pre class="programlisting">-ifdef(TEST). + +%% Insert tests here. + +-endif.</pre><p>Be careful, however, if you include the EUnit header file, +as it also defines the <code class="literal">TEST</code> macro. Make sure to only include +it inside an <code class="literal">ifdef</code> block, otherwise tests will always be +compiled.</p><pre class="programlisting">-ifdef(TEST). + +-include_lib(\"eunit/include/eunit.hrl\"). + +%% Insert tests here. + +-endif.</pre><p>Erlang.mk will automatically recompile your code when you +perform a normal build after running tests, and vice versa.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_configuration_3"></a>15.2. Configuration</h2></div></div></div><p>The <code class="literal">EUNIT_OPTS</code> variable allows you to specify additional +EUnit options. Options are documented in the +<a class="ulink" href="http://www.erlang.org/doc/man/eunit.html#test-2" target="_top">EUnit manual</a>. +At the time of writing, the only available option is <code class="literal">verbose</code>:</p><pre class="programlisting">EUNIT_OPTS = verbose</pre></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="_usage_2"></a>15.3. Usage</h2></div></div></div><p>To run all tests (including EUnit):</p><pre class="programlisting">$ make tests</pre><p>To run all tests and static checks (including EUnit):</p><pre class="programlisting">$ make check</pre><p>You can also run EUnit separately:</p><pre class="programlisting">$ make eunit</pre><p>EUnit will be quiet by default, only outputting errors. +You can easily make it verbose for a single invocation:</p><pre class="programlisting">$ make eunit EUNIT_OPTS=verbose</pre><p>Erlang.mk allows you to run all tests from a specific +module, or a specific test case from that module, using +the variable <code class="literal">t</code>.</p><p>For example, to run all tests from the <code class="literal">cow_http_hd</code> +module (instead of all tests from the entire project), +one could write:</p><pre class="programlisting">$ make eunit t=cow_http_hd</pre><p>Similarly, to run a specific test case:</p><pre class="programlisting">$ make eunit t=cow_http_hd:parse_accept_test_</pre><p>To do the same against a multi-application repository, +you can use the <code class="literal">-C</code> option:</p><pre class="programlisting">$ make -C apps/my_app eunit t=my_module:hello_test</pre><p>Note that this also applies to dependencies. From Cowboy, +you can run the following directly:</p><pre class="programlisting">$ make -C deps/cowlib eunit t=cow_http_hd</pre><p>Finally, <a class="ulink" href="coverage.asciidoc" target="_top">code coverage</a> is available, +but covered in its own chapter.</p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch14.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="pt03.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch16.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> </td></tr></table></div> </main> </body> </html> |