Skip code variables using test methods?

I create a new user in testRegisterNewUser and save the username in the class field variable:

    private $_userName;

protected function userName ()
{
    if (empty($this->_userName)) {
        $this->_userName = uniqid('test_');
    }

    return $this->_userName;
}

public function testRegisterNewUser()
{
    $user = new User($this->userName() ); // create user with random name 
}

After that, I try to use this value in another class method, but $ _ username is not initialized with the original value from testRegisterNewUser !

public function testFundUser()
{
    $user = User::findByUsername( $this->userName() ); // fails, $this->userName() gives "non original" value
}

The question is, when I run tests with codecept run,

Does this mean that the class is Codeception\TestCase\Testrecreated for every method call *?

+4
source share

Source: https://habr.com/ru/post/1607303/


All Articles