Codeception Tutorial Part 1 - Getting Started


This tutorial assumes the following:

1. You have an understanding of automated tests.

2. You have a basic understanding of PHPUnit.



1. Codeception is a testing framework.

2. Out of the box you get tools to write unit, functional and acceptance tests.

3. Most of this presentation is derived from the Codeception documentation.

4. You can install Codeception with Composer.


Codeception Folder Structure

1. Upon initialisation, Codeception generates numerous folders and files.

2. These files are placed within your “tests” folder.

3. The main folders you will work in are the “unit”, “functional” and “acceptance” folders.

4. These are known as your ”test suites”.


Creating a Test

1. “php codecept generate:phpunit unit Example”

2. “php codecept generate:test unit Example”

3. The first command generates a classical PHPUnit test.

4. The second command will generate a file which enables you to use Codeception’s helpers.

5. Both commands will generate “ExampleTest” in the “tests/unit” folder.


_before() and _after()

1. These method are aliases for PHPUnit’s ”setup” and “tearDown”.

2. The actual “setup” and “tearDown” is implemented by the parent class.

3. They setup Codeception’s “Cept-files” to be run as part of unit tests.

4. Code put in these methods, run before and after each test.



1. There is a config file named “unit.suite.yml”.

2. Within this file you can declare Codeception modules.

3. Once you have updated this file you should run: “php codecept build”


Writing Unit Tests

1. Codeception uses PHPUnit for running tests.

2. Any PHPUnit test can be added to a Codeception test suite and then run.

3. You can continue to write Unit tests as you would in PHPUnit.

4. Codeception provides helpers to simplify common tasks.


Arrow Icon