How can I run only one test from a suite?

A more proper way of doing this will be to assign a group annotation to the test case in question. This is preferable for the following reason; If you have two test cases for example in the same class VisitorCest;

public function aboutPage
public function aboutPage2

Executing

codecept run tests/acceptance/VisitorCest.php:aboutPage

will run both VisitorCest:aboutPage and VisitorCest:aboutPage2 test cases.

Assign a group to a test case like this

/**
 * @group aaa
 */
public function aboutPage(AcceptanceTester $I)
{
}

And execute this particular test case like this

codecept run -g aaa


You simply append a colon and the function name, like this:

codecept run tests/acceptance/VisitorCest.php:myTestName

or a shorter version:

codecept run acceptance VisitorCest:myTestName

(Notice the space between the suite-name and the file-name.)


In addition to the answer provided by @Tzook Bar Noy you can add a trailing $ when there are multiple tests which start with the same name. Consider the following example:

<?php

use \AcceptanceTester;

class VisitorCest
{
    public function aboutPage(AcceptanceTester $I)
    {
    }

    public function aboutPageOption(AcceptanceTester $I)
    { 
    }
}

Where the following command will execute both of the tests:

codecept run tests/acceptance/VisitorCest.php:aboutPage

This will execute only the first:

codecept run tests/acceptance/VisitorCest.php:aboutPage$

this is what works:

codecept run {suite-name} {file-name}.php:{function-name}

notice the space between the suite-name and the file-name