8 Jul 2012

Erlang unit testing in Nitrogen: eunit

I like to have some automated testing for my next project, and I was happy to find the unit testing module for Erlang (called eunit) bundled with Nitrogen. If you want to keep your production code and test code separate (good introduction here), then you need to fix your Nitrogen Emakefile.

The default Nitrogen project lives in the nitrogen/site directory.
You'll find the following directories in there:
- ebin
- include
- src
- static
- templates

I've added the directory test to this to host my unit tests
Your Emakefile is also in the nitrogen/site directory.
The default version looks like this:

{
  [
    "./src/*",
    "./src/*/*",
    "./src/*/*/*",
    "./src/*/*/*/*"
  ],
  [
    { i, "./include" },
    { outdir, "./ebin" },
    debug_info
  ]
}.

You should change this into:

{
  [
    "./src/*",
    "./src/*/*",
    "./src/*/*/*",
    "./src/*/*/*/*",
    "./test/*",
    "./test/*/*",

    "./test/*/*/*",
    "./test/*/*/*/*" 
  ],
  [
    { i, "./include" },
    { outdir, "./ebin" },
    debug_info
  ]
}.


After this, everytime you run ./dev compile (shell) or sync:go() (Erlang console) the unit tests are compiled as well. You can run your tests the in the Erlang console with eunit:test(module_name)
   

No comments:

Post a Comment