lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

The _only_ additional thing I've ever needed for unit tests, and I use them a lot, is 'assert.fails()'.

Use such that:

assert.fails( function() ...doing something here that should fail... end,
		 "Expected error message" )

The error message param is optional.

This is with a mod that makes 'assert' a table, and '__call' metamethod point to the original assert (so it's there, too..)

The Rule of Thumb is: wear either the Tester hat, or the Developer hat. At a time. Keep tests separate of the implementation (like test- foo.lua).


Brian McCallister kirjoitti 27.11.2006 kello 7.10:

FWIW, I wound up making a miniscule unit test harness for a project I am working on:

The harness:

Example Usage:

Running the Example (with some configs changed to generate failures):

brianm@golem:~/src/wombat/test$ ./test.lua
[basic_post_alt]                        pass
[map_regex2]                            pass
[server_says_hi]                        pass
[post_with_table]                       pass
[basic_post]                            pass
[request_attributes]                    pass
[simple]                                pass
[map_regex]                             pass
[translate_name_hook2] FAIL ./test.lua:97: expected 200 got 404 [fixups_hook] FAIL ./test.lua:109: incorrect status code returned, expected 201 got 200
[server_version]                        pass
[basic_get]                             pass
[super_basic_config]                    pass
[simple_mapped]                         pass
[quietly]                               pass
[translate_name_hook] FAIL ./test.lua:91: expected 200 got 404
[simple_filter]                         pass

brianm@golem:~/src/wombat/test$ ./test.lua simple_filter translate_name_hook
[simple_filter]                         pass
[translate_name_hook] FAIL ./test.lua:91: expected 200 got 404

It doesn't have anything very fancy, but it works darned well. Lua's assert(..) does pretty much all the heavy lifting.


On Nov 19, 2006, at 4:08 PM, Doug Currie wrote:

According to your link lunit has no been updated since August 2004 and the latest version is 0.3 (alpha). Does it mean that the project is in
a dormant phase?

Yes, you are right, but it can be use as a base.

I noticed "lunit 0.4pre (alpha)" in


Doug Currie
Londonderry, NH