Overview of Busted unit testing framework
masterBusted is a unit testing framework for Lua (>= 5.1), LuaJIT (>= 2.0.0), and MoonScript. It focuses on ease of use through a natural, readable syntax for test specs.
Key features include:
- Nested Test Blocks: Use
describeto group tests with contextual descriptions. - Extensible Assertions: An assertion library that supports method chaining (e.g.,
assert.is_not.equal). - Mocks and Spies: Built-in support for functional testing using
spy. - Modular Output: Supports multiple output formats including pretty, plain, JSON (with/without streaming), and TAP-compatible output for CI integration.
describe('Busted unit testing framework', function()
describe('should be awesome', function()
it('should be easy to use', function()
assert.truthy('Yup.')
end)
it('should have lots of features', function()
-- deep check comparisons!
assert.same({ table = 'great'}, { table = 'great' })
-- or check by reference!
assert.is_not.equals({ table = 'great'}, { table = 'great'})
assert.falsy(nil)
assert.error(function() error('Wat') end)
end)
it('should provide some shortcuts to common functions', function()
assert.unique({{ thing = 1 }, { thing = 2 }, { thing = 3 }})
end)
it('should have mocks and spies for functional tests', function()
local thing = require('thing_module')
spy.on(thing, 'greet')
thing.greet('Hi!')
assert.spy(thing.greet).was.called()
assert.spy(thing.greet).was.called_with('Hi!')
end)
end)
end)