> ## Documentation Index
> Fetch the complete documentation index at: https://help.pixwel.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Testing

# 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](https://github.com/Pixwel/platform/tree/2.x/api/spec) - [Kahlan](http://kahlan.readthedocs.org/) is nice, we like Kahlan.
2. [Legacy tests](https://github.com/Pixwel/platform/tree/2.x/api/tests) - older tests in the [default li3 testing tool](http://li3.me/docs/manual/quality-code/testing.md).

See [this article](http://radify.io/blog/faster-php-code-coverage/) for how we manage running legacy tests together with Kahlan tests.

## Kahlan tests

```bash theme={null}
docker-compose exec app bash
cd api
pixwel_environment=test bin/kahlan
```

or

```bash theme={null}
pixwel kahlan
```

### Code coverage

> See also [xdebug](/api/xdebug)

Coverage: by method

```bash theme={null}
bin/kahlan --4
```

Coverage: line-by-line

```bash theme={null}
bin/kahlan --coverage
```

> Note: The CI build actually collates together legacy and kahlan test coverage.

The following will created an HTML coverage report:

```bash theme={null}
pnpm install -g istanbul
bin/kahlan --istanbul="coverage.json"
istanbul report
```

The coverage report may be viewed in your browser at

```bash theme={null}
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

Older li3 tests live in `api/tests/`. They are **no longer run in CI** (only Kahlan is), but can still be run from the app container:

```bash theme={null}
cd /var/www/api
li3 test tests/cases/
li3 test tests/integration/
```

***

[Back to docs index](/) | [API docs index](/api/overview) | [Next page in recommended reading order >>](/api/xdebug)
