This Lua test module provides a simple framework for defining and running unit tests. It allows you to create test suites, add test cases, and run the tests with a summary of the results.
- Create test suites
- Add test cases to the suite
- Run all test cases in the suite
- Print detailed results for each test case
- Summary of passed and failed tests
Install with apm
.load-blueprint apm
APM.install('@rakis/test-unit')
Create a new test suite with a given name.
local Test = require("@rakis/test-unit")
local myTests = Test.new("My Test Suite")Add test cases to the suite. Each test case is a function that contains assertions to check the expected outcomes.
myTests:add("Test Case 1", function()
assert(1 + 1 == 2, "Math is broken!")
end)
myTests:add("Test Case 2", function()
assert(type("hello") == "string", "Type check failed!")
end)Run all test cases in the suite and print the results.
local results = myTests:run()
print(results)Here's a complete example demonstrating how to use the test module:
local Test = require("Test")
-- Create a new test suite
local myTests = Test.new("Example Test Suite")
-- Add test cases
myTests:add("Test Addition", function()
assert(1 + 1 == 2, "Addition failed!")
end)
myTests:add("Test Type", function()
assert(type("hello") == "string", "Type check failed!")
end)
-- Run the tests and print the results
local results = myTests:run()
print(results)This project is licensed under the MIT License.