haxe-should can be introduced constraint-based assertion to unit test framework. haxe-should uses Abstract Type. Therefore, it can be vailable in Haxe 3 or later.
Currently, only MUnit is supported.
Zip archive of this tool is downloading,
or clone from git.
git clone https://github.com/ritalin/haxe-should.git
then add to classpass of a target project.
In hxml file, for example,
-cp /path/to/haxe-should
Before this feature is used, a "failed behavior" must be registered in a entry point function of test environment (usually, main routine).
For munit, calling static function: should.ext.MUnitBehavior.apply() is lead to register this behaviot.
In test method, perform assertion. For example equality assertion of value...
// recommend static importing for a easy-to-use.
import should.ActualFactory.*;
import should.CoreMatchers.*;
...
var n = 100;
its('numeric value test').val(n).should( beEqualTo(100) );
Assertion cosists of three part.
- First part(its) describes comment for test performing.
- Second part(val / call) passes a actual value (or actual call).
- Finally, third part(should) specifies expect value macher in should call.
Currently, it's available following machers.
For the actual value...
Describes later, sorry.
Describes later, sorry.
Describes later, sorry.
For thenactual call...
Describes later, sorry.
And, for negative maching...
Describes later, sorry.
Additionally, using operator && (and) or || (or) allow to specify mixed machings.
For exampe.
its('true or null').val(false).should(beTrue || beNull); // this test will fail.
Note that mix macher operator may be influence by priorities of operators.
Making custom fail behavior, it registers exception thrown on test failing.
See should/ext/MUnitBehavior.hx for details.
All matchers is implemented in should.Matcher interface (should/Matcher.hx).
should.Matcher has one method, evaluate(actual: T, expected: T, negate: boolean): EvaluateResult.
first argument and second argument in this method, actual value (or call) and expected value is passed, respectively. And negative flag is passed to third argument. if use not matcher, true will be passed.
And mix macher operator is implemented in Abstract Type. Therefore customized matcher instance must be wrapped haxe.MatcherPlus.
See should/CoreMatchers.hx for details.