BTD
build-test-deploy Development Environment

Best practices

This is meant to be a collection of tips and miscellaneous information which might help and/or give a better understanding of the inner workings (and quirks ?).
preamble
My interest in Lua is as a complete development environment, this is also where unit testing "shines" the most. It replaces Java as my language of choice, which also explains the terminology (classes, classpath,...).
structure of a test
Ideas :
  • no coupling between test methods
  • common parts can be put in setUp and tearDown methods
  • variables can be passed as follows :
    global variables
    sandboxed through use of LuaNMP, every test method has it's own copy. But conflicts may arise with your class under test.
    local variables
    sandboxed through use of LuaNMP, every test method has it's own copy
    through the self instance
    valid alternative to local variables. But does not work with setUpClass nor tearDownClass, and they only exist within the test method instance (are not copied back to the test results).
structure of test classes/methods
Generally tests are written on a per class basis, which makes them easier to maintain. So every ClassXX has a TestClassXX test class. These test classes can be run directly from the command line, but easier is to organise them in a TestRunner class. Here you can, for example, group all tests of some specific application including (or excluding) all used "library" functions. Since the actual runner is an instance of btd.lua.Test you can invoke the run method as many times as necessary and the results will be collected in one report (the opposite is also possible of course by instantiating a runner per set of tests). This also makes it possible to chain testrunner classes.
which methods to test
You can of course run all test runners for the entire application and for all libraries included (even if only one function is actually used) and eventually generate enormous error listings. In that case one might opt for only running tests for the actually used library methods.
test results
The test results are reported to 'stdio' and/or to 'stderr' if the errorIDE flag is set. They are however also collected in the testrunner instance to do with as you please :).
class path
You should setup the lua path to include your test environment.