Code origin before all tests inside CEST

I want to run something before all the tests inside a specific Cest, and then clear it after running all the tests, similar to the setUpBeforeClass and tearDownAfterClass methods in PHPUnit.

Is there a way to do something like this in Codeception?

+4
source share
2 answers

From a code point of view, the Cest class is just a bunch of Cept scripts. No object area and no before / after class.

My advice is to use a test format and use PhpUnit hooks.

The test format extends PHPUnit_Framework_TestCase, so setUpBeforeClass should work.

+1
source

You functional.suite.ymlcan add a new helper to:

class_name: FunctionalTester
modules:
    enabled:
      - tests\components\helpers\MyHelper

_before _after:

class FixtureHelper extends \Codeception\Module
{
    /**
     * Method is called before test file run
     */
    public function _before(\Codeception\TestCase $test)
    {
        // TODO: Change the autogenerated stub
    }

    /**
     * Method is called after test file run
     */
    public function _after(TestCase $test)
    {
        // TODO: Change the autogenerated stub
    }
}

TestCase _before _after.

+1

All Articles