Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eyal-wowhub/unittest
A library that offers an easy, efficient, and organized way to create, manage, and run unit tests.
https://github.com/eyal-wowhub/unittest
lib library lua world-of-warcraft world-of-warcraft-addon wow wow-addon
Last synced: 16 days ago
JSON representation
A library that offers an easy, efficient, and organized way to create, manage, and run unit tests.
- Host: GitHub
- URL: https://github.com/eyal-wowhub/unittest
- Owner: Eyal-WowHub
- Created: 2025-01-02T22:06:44.000Z (22 days ago)
- Default Branch: main
- Last Pushed: 2025-01-05T13:35:09.000Z (19 days ago)
- Last Synced: 2025-01-05T14:33:33.645Z (19 days ago)
- Topics: lib, library, lua, world-of-warcraft, world-of-warcraft-addon, wow, wow-addon
- Language: Lua
- Homepage:
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# UnitTest
A library that offers an easy, efficient, and organized way to create, manage, and run unit tests.
To run the tests, create a macro and paste the following script: `/run LibStub("UnitTest-1.0"):Run()`.
#### Dependencies: [LibStub](https://www.curseforge.com/wow/addons/libstub), [Contracts](https://github.com/Eyal-WowHub/Contracts)
### Example:
1. Calculator
```lua
-- Math.lua
local T = UnitTest_Table("Math", {
Add = function(a, b)
return a + b
end,
Divide = function(a, b)
assert(b ~= 0, "Divided by zero. The denominator cannot be zero.")return a / b
end
}, ...)do
local Add = T:Test("Add")Add["Should return 3"] = function(self, math)
self:Assert(math.Add(1, 2) == 3)
end
enddo
local Divide = T:Test("Divide")Divide["Should throw when divided by zero"] = function(self, math)
self:Capture(function()
math.Divide(1, 1)
end)
end
end
```
2. UnitTest
```lua
-- Modules.lua
local T = UnitTest_Library("UnitTest-1.0", ...)do
local Modules = T:Test("Modules")Modules["Create a module"] = function(self, ref)
self:Assert(Modules ~= nil)
end
end
```### Outputs:
```
-----------------------------------------------------------------------------------------------
+ Calculator (Modules: 1)
-----------------------------------------------------------------------------------------------
+ Math (Scopes: 2)
+ Add (Tests: 1)
+ Should return 3
+ Divide (Tests: 1)
+ Should throw when divided by zero
The function should have thrown an error, but it did not.
at 'Interface/AddOns/Calculator/Tests/MathTests.lua:24'
in 'Interface/AddOns/Calculator/Tests/MathTests.lua:23'.
-----------------------------------------------------------------------------------------------
+ UnitTest (Modules: 1)
-----------------------------------------------------------------------------------------------
+ UnitTest-1.0 (Scopes: 1)
+ Modules (Tests: 1)
+ Create a module
-----------------------------------------------------------------------------------------------
Tests: 3 | Addons: 2 | Modules: 2 | Scopes: 3 | Passed: 2 | Failed: 1
-----------------------------------------------------------------------------------------------
```