couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan Lehnardt <>
Subject [PATCH] Eunit Tests
Date Sun, 15 Feb 2009 01:15:57 GMT

I prepared a patch that adds EUnit-style tests to CouchDB:

The patch currently simply disables all tests that were available
in the ./test/ directory. The `couch_config_*` tests have been
migrated to the new EUnit style. The command-line based
JS test suite has yet to be enabled again. This is trivial.

The patch touches Makefiles'nstuff. Here's how to use it:

make local-clean
cd test
make test

You should see (after a while):

/usr/local/bin/erlc -o ../src/couchdb/tests/ ../src/couchdb/tests/*.erl
erl -noshell -pa ../src/couchdb/ -pa ../src/couchdb/tests/ \
	-eval "eunit:test([couch_config, couch_config_writer])" \
	-s init stop
   All 8 tests successful.

The output can be beautified. I kept it raw to show all that happens.

You see that this is still contained to the ./test/ directory. We'd  
need to hook it up to the top level `make test`. I hope to get some help
with this.

Also, the conditional compilation with `erlc -DTEST` is not ideal yet.
I chose to use this to keep all test code out of code that will be  
but currently, all compiled `.beam` files get `rm`'d and recompiled with
`erlc -DTEST` on every test-suite run. Also, if you happen to run `make
install` from the top level directory, you'd install the test-enabled  
files. My lack of Autotools-fu prevented me from doing this more  
and again, I hope to get some help from the community.


Writing Tests

Hey, nice, you stuck around and like to know how to write tests now?

1) Create a file `my_module_tests.erl` in src/couchdb/tests/ e.g.

2) Insert boilerplate header:



3) Start writing tests. See
for details. You can take the couch_config*_tests.erl files as guide,
but they are of poor quality and not yet good EUnit style. I tried to  
as little as possible with this patch.

4)* Add my_module in line 28 of test/

5) cd test && make test

6) Go to step 3).

* This should be made more elegant as well as more test suites
    are written.


What do you think?


View raw message