Extends Lua's built-in assertions with additional tests, custom assertions, argument matchers, and snapshot capabilities.
Luassert is an assertion library for Lua that extends the language's native `assert` function with a rich set of testing utilities. It provides a flexible framework for writing expressive tests, supporting custom assertions, modifiers, matchers, and state management through snapshots. The library enhances test readability and maintainability by offering chainable syntax and extensibility.
Lua developers and testers who need a robust, extensible assertion library for unit and integration testing, particularly those using testing frameworks like Busted. It's suitable for developers writing complex test suites that require custom assertions, argument matching, or state isolation.
Developers choose Luassert over basic assertions because of its high extensibility, allowing custom assertions, matchers, and formatters, and its snapshot feature for isolating test effects. Its expressive, chainable syntax and comprehensive built-in utilities reduce boilerplate and improve test clarity compared to native Lua assertions.
Assertion library for Lua
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Provides modifiers like 'not' and 'array' for readable assertions, as shown with `assert.is_not.True(false)` and `assert.array(arr).has.no.holes()`, reducing boilerplate.
Allows custom assertions, matchers, and formatters with registration functions, enabling tailored testing logic, such as defining `has_property` assertions.
Supports flexible spy/stub verification with matchers and composites like `all_of` and `any_of`, and custom matchers like `is_even`, for precise test conditions.
Snapshots capture and revert spies, stubs, parameters, and formatters, ensuring test independence and preventing side effects, as demonstrated in the snapshot examples.
Lua keywords like 'true' and 'function' cannot be chained with '.' and require underscores or capitals, adding complexity and potential errors in assertion writing.
Assertions like `returned_arguments` do not accept direct failure messages and need the `message` modifier, making error customization less intuitive.
Custom assertions rely on the 'say' library for i18n, which must be installed separately via LuaRocks, adding setup steps and potential compatibility issues.
The extensive features, such as custom formatters and parameter management, require a deeper understanding compared to simpler assertion libraries, increasing initial time investment.