* [Any tutorials on Unit testing in CI4?](https://forum.codeigniter.com/showthread.php?tid=81830)
## Requirements
It is recommended to use the latest version of PHPUnit. At the time of this
writing, we are running version 9.x. Support for this has been built into the
**composer.json** file that ships with CodeIgniter and can easily be installed
via [Composer](https://getcomposer.org/) if you don't already have it installed globally.
```console
> composer install
```
If running under macOS or Linux, you can create a symbolic link to make running tests a touch nicer.
```console
> ln -s ./vendor/bin/phpunit ./phpunit
```
You also need to install [XDebug](https://xdebug.org/docs/install) in order
for code coverage to be calculated successfully. After installing `XDebug`, you must add `xdebug.mode=coverage` in the **php.ini** file to enable code coverage.
## Setting Up
A number of the tests use a running database.
In order to set up the database edit the details for the `tests` group in
**app/Config/Database.php** or **.env**.
Make sure that you provide a database engine that is currently running on your machine.
More details on a test database setup are in the
[Testing Your Database](https://codeigniter.com/user_guide/testing/database.html) section of the documentation.
## Running the tests
The entire test suite can be run by simply typing one command-line command from the main directory.
```console
> ./phpunit
```
If you are using Windows, use the following command.
```console
> vendor\bin\phpunit
```
You can limit tests to those within a single test directory by specifying the
directory name after phpunit.
```console
> ./phpunit app/Models
```
## Generating Code Coverage
To generate coverage information, including HTML reports you can view in your browser,