Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/w13b3/probo
Lua unit test framework
https://github.com/w13b3/probo
documentation framework lua mocking testing unit-testing unittesting-library
Last synced: about 2 months ago
JSON representation
Lua unit test framework
- Host: GitHub
- URL: https://github.com/w13b3/probo
- Owner: w13b3
- License: apache-2.0
- Created: 2022-06-20T17:19:43.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-06-26T08:36:31.000Z (over 2 years ago)
- Last Synced: 2023-03-05T04:48:08.440Z (almost 2 years ago)
- Topics: documentation, framework, lua, mocking, testing, unit-testing, unittesting-library
- Language: Lua
- Homepage:
- Size: 52.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Probo _Lua unit test framework_
Compatible with [Lua 5.4]
## Test suite example
```Lua
local Suite = require("probo/suite")local runInfo = {} -- define a `runInfo` table before the do-end scope
do
-- create a new test suite instance
-- with defined a garbage-collection cycle is performed at the end this scope
local test = Suite.New("Probo Suite example")
local assert = test -- more readable separation between tests and assertstest.run = 1 -- test suite variable
function test.AlwaysPasses() -- this is a defined test
assert:Invokable(test) -- multiple different asserts are available
endtest("Always Fails") -- test is a decorator
(function() -- with the decorator test names can have spaces
assert:Fail()
end)function test.FlakyTest() -- failed tests in the first run can be rerun
test.run = test.run + 1 -- if the option `rerunFailedTests` is set to true
assert:Condition(test.run > 2)
endlocal suiteOptions = { -- a table with options
stopOnFail = false, -- stops on first failed test
silent = false, -- no output
rerunFailedTests = true, -- rerun failed tests
sortedByName = false -- sort tests by name before the test run
}-- run the above defined tests with the given options
runInfo = test:Run(suiteOptions) -- runInfo, a table with info about the run
end
```## Create report
After a run a report can be made with the `runInfo` created by the run```lua
local Report = require("probo/htmlreport")local htmlReport = Report.Create(runInfo) -- create a HTML report
-- save the report
local reportFile = io.open("probo_report.html", "w")
reportFile:write(htmlReport)
reportFile:close()
```## Mock global functions
By mocking it is possible to temporarily change the behaviour of functions.```lua
local Suite = require("probo/suite")
local Mock = require("probo/mock")do
local test = Suite.New("Probo Mock example")
local assert = test
local mock = Mock.New()
mock("string.reverse", function(str) return str end)
test("global string.reverse function is mocked")
(function()
local given = "not reversed"
local actual = string.reverse(given)
assert:Equal(given, actual)
end)
end```
## Unit tests
Check out the [unit tests] that test the [Probo] unit test package.## License
[Apache 2.0][Lua 5.4]: https://www.lua.org/manual/5.4/ "Lua 5.4 Manual"
[unit tests]: ./test/README.md "/test/README.md"
[Probo]: ./probo/suite.lua "Lua unit test framework"
[Apache 2.0]: ./LICENSE "LICENSE"