Custom Assertions
TestBox comes with a plethora of assertions that cover what we believe are common scenarios. However, we recommend that you create custom assertions that meet your needs and criteria so that you can avoid duplication and have re-usability. A custom assertion function can receive any amount of arguments but it must use the fail()
method in order to fail an assertion or just return true or void for passing.
Here is an example:
Assertion Registration
You can register assertion functions in several ways within TestBox, but we always recommend that you register them inside of the beforeTests()
or setup()
life-cycle method blocks, so they are only inserted once.
Inline Assertions
You can pass a structure of key/value pairs of the assertions you would like to register. The key is the name of the assertion function and the value is the closure function representation.
After it is registered, then you can just use it out of the $assert
object it got mixed into.
Class Assertions
You can also store a plethora of assertions (Yes, I said plethora), in a class and register that as the assertions via its instantiation path. This provides much more flexibility and re-usability for your projects.
You can also register more than 1 class by using a list or an array:
Here is the custom assertions source:
Last updated