Skip to main content

Pixwel API - testing

You should aim for 100% code coverage of any code that you touch. There are two suites of tests in the Pixwel API:
  1. Kahlan tests - Kahlan is nice, we like Kahlan.
  2. Legacy tests - older tests in the default li3 testing tool.
See this article for how we manage running legacy tests together with Kahlan tests.

Kahlan tests

docker-compose exec app bash
cd api
pixwel_environment=test bin/kahlan
or
pixwel kahlan

Code coverage

See also xdebug
Coverage: by method
bin/kahlan --4
Coverage: line-by-line
bin/kahlan --coverage
Note: The CI build actually collates together legacy and kahlan test coverage.
The following will created an HTML coverage report:
pnpm install -g istanbul
bin/kahlan --istanbul="coverage.json"
istanbul report
The coverage report may be viewed in your browser at
api/coverage/lcov-report/index.html

Best practise for Pixwel with Kahlan

To make sure performance is good:
  • Prefer Stubbing over Fixtures - Fixtures are slow.
  • If you MUST use fixtures:
    • Make sure it’s compartmentalised and the tests that do not need fixtures are in a separate context block to the ones that do
    • Only use the exact fixtures that are needed - don’t blindly load them all
  • Prefer before over beforeEach where possible

Legacy tests

cd /opt/pixwel/pixwel-api
libraries/lithium/console/li3 test tests/cases/
libraries/lithium/console/li3 test tests/integration/

Back to docs index | API docs index | Next page in recommended reading order >>