FLAT provides a built-in test framework. It is especially useful to unit-test templates, error handling and upstream requests.
FLAT tests are defined as flow files with the root node flat-test
. There are a couple of specialized test actions that accompany the test flow. The invocation of at least one assert
action is mandatory.
<flat-test>
<!-- flow code -->
<assert>
[
[ … ]
]
</assert>
</flat-test>
Test files can be stored anywhere inside the FLAT app directory. We recommend creating a tests/
folder next to swagger.yaml
.
FLAT tests are started with the flat
cli command test
:
$ flat test tests/test-foo.xml tests/test-bar.xml
The test result is printed in TAP format:
1..2
ok 1 tests/test-foo.xml: 17 assertions
ok 2 tests/test-bar.xml: 4 assertions
passed: 2, failed: 0
If all tests pass, the exit code is 0
. If any test fails, the code is non-zero (1
). Therefore, in deployment scripts or Makefile
recipes (both of which are usually executed as set -e
) you can rely on the exit code to fail the process.
- Testing Templates (cookbook)
- Testing API Requests (cookbook)
- Testing Upstream Requests (cookbook)
- Test Actions (reference)
assert
(reference)backend-flow
(reference)set-env
(reference)test-request
(reference)