-
Notifications
You must be signed in to change notification settings - Fork 5
Home
APLUnit is a Unit Test (UT) library to facilitate TDD with APL. The syntactical overhead is minimal, enforcing test function naming to end with _TEST
and setting your expected value in #.UT.expect
.
Example
:NameSpace TestSpace
∇ Z ← iota_with_lhs_generates_sequence_TEST
#.UT.expect ← ⍳ 2
Z ← 1 2
∇
:EndNameSpace
The expected return value (#.UT.expect ← ⍳ 2) is checked against the returned value (Z ← 1 2). Since the function is named 'passing_basic_TEST', it is signaling that this is a Unit Test.
We run this by utilizing the only interface function #.UT.run
. This is the only function you need to care about for running tests. Be it one test, one array of tests or a file with tests.
Example
#.UT.run '#.TestSpace.iota_with_lhs_generates_sequence_TEST'
Passed
Now, calling every test function in this manner is of course not viable in the long run, we can save ourselves a lot of grief by passing an array of tests instead.
Tests ← ⊂'#.TestSpace.iota_with_lhs_generates_sequence_TEST'
#.UT.run Tests
Passed
----------------------------------
⍋ Passed: 1
⍟ Crashed: 0
⍒ Failed: 0
As the amount of tests grow, it's more time saving to just execute all tests in the testfile instead.
Now, assume the test was written in the file Testfile.dyalog
#.UT.run '/path/to/Testfile.dyalog'
Passed
----------------------------------
/path/to/Testfile.dyalog
⍋ Passed: 1
⍟ Crashed: 0
⍒ Failed: 0
Now, we just add more tests (functions ending in _TEST) to Testfile.dyalog - and use #.UT.run
with the path as an argument to execute all the tests.