setUpBeforeClass() & tearDownAfterClass() are ignored when executing only one test method if not first test · Issue #6809 · Codeception/Codeception · GitHub
Skip to content

setUpBeforeClass() & tearDownAfterClass() are ignored when executing only one test method if not first test #6809

Open

Description

@Stav88

What are you trying to achieve?

Given th following test class :

<?php

use PHPUnit\Framework\TestCase;

class TestTest extends TestCase
{
    public static function setUpBeforeClass(): void
    {
        error_log(__FUNCTION__);
    }
    public static function tearDownAfterClass(): void
    {
        error_log(__FUNCTION__);
    }
    public function test1(): void
    {
        error_log(__FUNCTION__);
        $this->assertTrue(true);
    }
    public function test2(): void
    {
        error_log(__FUNCTION__);
        $this->assertTrue(true);
    }
}

When I use --filter option, I expect that setUpBeforeClass() & tearDownAfterClass() are executed :

 vendor/bin/codecept run tests/unit/TestTest.php --filter 1
 vendor/bin/codecept run tests/unit/TestTest.php --filter 2

What do you get instead?

--filter 1 execute setUpBeforeClass() & tearDownAfterClass() => OK

Codeception PHP Testing Framework v5.0.13 https://stand-with-ukraine.pp.ua
setUpBeforeClass

Unit Tests (1) -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- TestTest: Test1test1
✔ TestTest: Test1(0.00s)
tearDownAfterClass
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Time: 00:00.033, Memory: 36.00 MB

OK (1 test, 1 assertion)

--filter 2 don't execute setUpBeforeClass() & tearDownAfterClass() => BAD

Codeception PHP Testing Framework v5.0.13 https://stand-with-ukraine.pp.ua

Unit Tests (1) -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- TestTest: Test2test2
✔ TestTest: Test2(0.00s)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Time: 00:00.033, Memory: 36.00 MB

OK (1 test, 1 assertion)

Details

  • Codeception version: 5.0.13
  • PHP Version: 8.1
  • Operating System: ubuntu 22.04
  • Installation type: Composer
  • List of installed packages : (skipped since is huge: +100)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions