Search

💡 You are reading docs for latest Codeception 5. Read for 4.x

Unit & Integration Tests

Codeception uses PHPUnit as a backend for running its tests. Thus, any PHPUnit test can be added to a Codeception test suite and then executed. If you ever wrote a PHPUnit test then do it just as you did before. Codeception adds some nice helpers to simplify common tasks.

Creating a Test

Create a test using generate:test command with a suite and test names as parameters:

php vendor/bin/codecept generate:test Unit Example

It creates a new ExampleTest file located in the tests/Unit directory.

As always, you can run the newly created test with this command:

php vendor/bin/codecept run Unit ExampleTest

Or simply run the whole set of unit tests with:

php vendor/bin/codecept run Unit

A test created by the generate:test command will look like this:

<?php

namespace Tests\Unit;

use Tests\Support\UnitTester;

class ExampleTest extends \Codeception\Test\Unit
{
    protected UnitTester $tester;

    protected function _before()
    {
    }

    // tests
    public