Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>EDIT:</strong> Just realised you used <code>common_test</code>. Please ignore this reply if it doesn't apply!</p> <p>I have a slightly more advanced way of testing un-exported functions that has the benefit of not exporting them, thus keeping the production code as intact as possible (there might be faults that only occur if some functions are not exported, but is not detected during testing if all functions are exported).</p> <p>This is how it works using Rebar and EUnit.</p> <p>In your source file, add these lines:</p> <pre><code>-ifdef(TEST). -include("yourmodule_tests.hrl"). -endif. </code></pre> <p>In your <code>test</code> folder, add a file called <code>yourmodule_tests.hrl</code> (in contrast to, for example, <code>yourmodule_tests.erl</code> in the normal case) and add the following contents:</p> <pre><code>-include_lib("eunit/include/eunit.hrl"). some_test() -&gt; ?assertEqual(ok, internal_function()). </code></pre> <p>Add the following configuration to <code>rebar.config</code> (if you already have <code>erl_opts</code>, just add the new tuple to that list):</p> <pre><code>{erl_opts, [{i, "test"}]}. </code></pre> <p>When you run <code>rebar eunit</code> Rebar will define the <code>TEST</code> environment variable and your code will be "test compiled". That is, including your tests into your module and the tests will be able to access internal functions.</p> <p>If you use anything else than Rebar, just make sure you compile your code with <code>erlc -DTEST ...</code> when your compiling for tests.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload