18

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.

Kotie Smit
  • 646
  • 1
  • 5
  • 18

6 Answers6

31

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();
    }
}
rickroyce
  • 950
  • 11
  • 24
27

I use the skip annotation for my unit tests.

/**
 * @skip
 */
public function MyTest(UnitTester $I)
{
    ...
}
Nathan Koop
  • 24,803
  • 25
  • 90
  • 125
  • `@skip` annotation could be applied for Test method only, not for the whole Cest class – Oleg Jun 20 '22 at 09:15
4

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.

Jim Maguire
  • 1,020
  • 1
  • 8
  • 19
1

Use PHPUnit_Framework_SkippedTestError. For example:

    if (!extension_loaded('mongo')) {
        throw new \PHPUnit_Framework_SkippedTestError(
            'Warning: mongo extension is not loaded'
        );
    }
serghei
  • 3,069
  • 2
  • 30
  • 48
0

So to make your scenario skipped during test run :

  1. You must have $scenario as second input param in your test
  2. make call : $scenario->skip();
  3. make call after skip : $I->comment("Reason why scenario skipped")
0

You can use the below codes in case you are using Codeception V4 and PHPUnit V9:

public function test1(ApiTester $apiTester){
  $apiTester->markTestSkipped("Skiping reason message");

}

Or:

public function test1(ApiTester $apiTester){
  $apiTester->markTestIncomplete("reason message");

}
Meysam Zarei
  • 419
  • 2
  • 14