Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to skip a Codeception cest test

I want to skip only one test in a codeception cest test.

Using Cept tests you can do $scenario->skip(); but does not work for Cest tests.

So I want to do something like this. Run the first test, but skip the second one.

Class MyTests{

   public funtion test1(){
    // My test steps
     }

   public function test2(){
     $scenario->skip("Work in progress");
     }
}

Thank you in advance.

like image 425
Kotie Smit Avatar asked Mar 11 '15 12:03

Kotie Smit


People also ask

How do you skip a test in Codeception?

The codeception library is built on top of phpunit, so to skip test there is a function markTestSkipped . Every code after this function will not be executed. It is good to add message explaining why test was skipped.

What is Cest Codeception?

Cest is a common test format for Codeception, it is “Test” with the first C letter in it. It is scenario-driven format so all tests written in it are executed step by step. Unless you need direct access to application code inside a test, Cest format is recommended.


4 Answers

the method you are looking for is called "incomplete".

$scenario->incomplete('your message, why skipping');

If you want to use Scenarios in Cest files, you can get it with the second parameter of your test method:

class yourCest 
{
    public function yourTest(WebGuy $I, $scenario) 
    {
        $scenario->incomplete('your message');
    }
}

Or you can use $scenario->skip('your message')

class yourCest 
{
    public function yourTest(WebGuy $I, $scenario) 
    {
        $scenario->skip('your message');
    }
}

Edit:

As already mentioned, the WebGuy is outdated and the annotations @skip or @incomplete are the way you should skip your tests in Cest files.

class yourCest 
{

    /**
     * @skip Skip message
     */
    public function yourTest(AcceptanceTester $I) 
    {
        $I->shouldTestSomething();
    }
}
like image 113
rickroyce Avatar answered Oct 19 '22 05:10

rickroyce


I use the skip annotation for my unit tests.

/**
 * @skip
 */
public function MyTest(UnitTester $I)
{
    ...
}
like image 22
Nathan Koop Avatar answered Oct 19 '22 07:10

Nathan Koop


First of all, remember that which commands are available to you are going to depend on which modules and suites you have loaded. For instance, if you are doing integration tests with the default WordPress enabled YML:

$scenario->skip('your message');

won’t work in a Cest or Test out of the box, but will work in Acceptance.

In fact, generally this command will work with Cept tests [Cepts are usually Acceptance like tests, Cests and Tests are usually PHPUnit like OOP tests]. Also, you need to pass $scenario to your function. This isn’t clearly documented and I can’t get it to work in Cests. Don’t get me started on how bad a choice “$scenario” is as a keyword for a BDD framework! A “scenario” is a keyword in Gherkin referring to what is a “step object” in Codeception. In Codeception it seems to be used as a redundant form of “environment”, even though there are environments, suites, and groups already. Like most of this great framework, the docs and function names need to be redone by native English speakers, for the second time! [remember “web guy”? Damn sexists Europeans! Lol].

If you use the

/**
 * @skip
 */
public function myTest(){
  //this test is totally ignored
}

Annotation right above your function in a Cest or Test it will be skipped, and won’t even appear in the report. [REALLY skip it]. Use this if you want to compleately hide a test.

If you use the PHPUnit command directly:

public function myTest(){
  throw new \PHPUnit_Framework_SkippedTestError('This test is skipped');
  //this test will appear as a yellow “skipped” test in the report
}

This will generate a skipped test in the report, will turn yellow in the HTML report [--html]. Use this if you want to skip a test but notice in the report that it’s skipped.

like image 29
Jim Maguire Avatar answered Oct 19 '22 05:10

Jim Maguire


Use PHPUnit_Framework_SkippedTestError. For example:

    if (!extension_loaded('mongo')) {
        throw new \PHPUnit_Framework_SkippedTestError(
            'Warning: mongo extension is not loaded'
        );
    }
like image 22
serghei Avatar answered Oct 19 '22 06:10

serghei