A Grey Hack unit testing framework
|
|
||
|---|---|---|
| src | ||
| .gitattributes | ||
| .gitignore | ||
| example.png | ||
| LICENSE | ||
| main.src | ||
| README.md | ||
GreyTest
Unit testing framework for Grey Hack (game). GreyTest provides a lightweight, focused API to write and run unit tests for in-game scripts and libraries used within Grey Hack.
Features
- Test definitions that run inside Grey Hack-compatible environments
- Assertions for values, maps, and functions
- Simple CLI-style runner with pass/fail counts and minimal output suitable for in-game consoles
- Seperate runner for each test showing exactly which test failed and why
Example image
Setup
- Import the framework into your codebase before any code execution.
It is recommended to this using the vscode plugin made by ayecue.
#include "/path/to/framework" - Creating a test
First a test object is created using the create function.
After this the actual test run function is defined.
To skip a function simply add a 0 as an extra argument like so.__TEST__.create("myFunction") -- Adding false as a second argument will skip this test. __TEST__.tests["myFunction"].run = function self.assertEq(myFunction("string.to.split"), ["string","to","split"]) end function__TEST__.create("myFunction", 0) -- This is a skipped test. - Running the tests
In order to run the tests__TEST__.runis called.
It is important for this to be run before themainfunction of the program.
This is, because the tests need to be run before the program starts.
Assert functions
Here is a list of all the assert functions:
assertEq(actual, expected) --tests if the actual is equal to expected.
assertNotEq(actual, expected) --tests if the actual is not equal to expected.
assertIsa(actual, expected) --tests if the actual is of the same type as expected.
assertNotIsa(actual, expected) --tests if the actual is not of the same type as expected.
assertBigger(actual, expected) --tests if the actual is bigger than expected.
assertSmaller(actual, expected) --tests if the actual is smaller than expected.
assertBigEq(actual, expected) --tests if the actual is bigger or equal to expected.
assertSmallEq(actual, expected) --tests if the actual is smaller or equal to expected.
assertTrue(actual) --tests if the actual is true.
assertFalse(actual) --tests if the actual is false.
assertNull(actual) --tests if the actual is null.
assertNotNull(actual) --tests if the actual is not null.
