title: How to automate module reloading when unit testing with Erlang?
body: <p>I'm using Emacs and trying to get my unit testing work flow as automated as possible. I have it set up so it is working but I have to manually compile my module under test or the module containing the tests before the Erlang Shell recognizes my changes. </p>
  
  <p>I have two files <code>mymodule.erl</code> and <code>mymodule_tests.erl</code>. What I would like to be able to do is:</p>
  
  <ol>
  <li>Add test case to mymodule_tests</li>
  <li>Save mymodule_tests</li>
  <li>Switch to the Erlang Shell</li>
  <li>Run tests with one line, like <code>eunit:test(mymodule)</code> or <code>mymodule_tests:test()</code></li>
  <li>Have Erlang reload mymodule and mymodule_tests before actually performing the tests</li>
  </ol>
  
  <p>I have tried writing my own test method but it doesn't work.</p>
  
  <pre><code>-module (mytests).
  -export([test/0]).
  
  -import(mymodule).
  -import(mymodule_tests).
  -import(code).
  
  test() -&gt;
      code:purge(mymodule),
      code:delete(mymodule),
      code:load_file(mymodule),
      code:purge(mymodule_tests),
      code:delete(mymodule_tests),
      code:load_file(mymodule_tests),
      mymodule_tests:test().
  </code></pre>
  
  <p>I have also tried by putting <code>-compile(mymodule).</code> into mymodule_tests to see if I could get mymodule to automatically reload when updating mymodule_tests but to no avail. </p>
  
  <p>I have also googled quite a bit but can't find any relevant information. As I'm new to Erlang I'm thinking that I'm either searching for the wrong terms, e.g. <code>erlang reload module</code>, or that you are not supposed to be able reload other modules when compile another module.  </p>