T - a multi-paradigm test framework
Posted: Wed Jun 24, 2015 1:30 pm
I wanted a test framework that would run subsections in isolation: for each "leaf" section of the scenario, the entire scenario runs, skipping all branches not connected to the current leaf. This kind of test framework eliminates the need for fixtures, and allows for creating BDD-style tests in an expressive, natural way.
This is much different from the nested sections in (for example) telescope... in those frameworks, the tests themselves cannot be nested (only the "context"), and the nested sections do not run in isolation.
Here's an example:
That test effectively defines two scenarios, one for each leaf branch:
This is much different from the nested sections in (for example) telescope... in those frameworks, the tests themselves cannot be nested (only the "context"), and the nested sections do not run in isolation.
Here's an example:
Code: Select all
T('Given a value of two', function (T)
local value = 2
T('When the value is increased by five', function (T)
-- here, value is 2
value = value + 5
T:assert(value == 7, 'Then the value equals seven')
end)
T('When the value is decreased by five', function (T)
-- value is 2 again; this test is isolated from the "increased by five" test
value = value - 5
T:assert(value == -3, 'Then the value equals negative three')
end)
end)
- Given a value of two
When the value is increased by five
Then the value equals seven
- Given a value of two
When the value is decreased by five
Then the value equals negative three