Codeception icon indicating copy to clipboard operation
Codeception copied to clipboard

`wantTo` is not displayed in unit tests' runner

Open ThomasLandauer opened this issue 4 years ago • 3 comments

When using $I->wantTo('foo'); in an acceptance or functional test, I get "foo" displayed next to the test file (instead of the test name) in the console when running the tests:

MyCest: Foo (0.63s)

However, when I do $this->tester->wantTo('foo'); in a unit test, I don't get it displayed.

ThomasLandauer avatar Jan 06 '21 17:01 ThomasLandauer

This issue is part of bigger issue that steps aren't displayed in unit tests. It is the worst in tests of Codeception itself because it uses unit tests to test modules.

I would say that this is documentation issue too. Functional and acceptance tests are Codeception tests, but unit tests are PHPUnit tests and Codeception has very limited impact on how they work. Codeception adds very little to unit tests (I've never used tester object in my unit tests) and removes few features it doesn't support, like @runInSingleProcess and loading of dependent tests.

Naktibalda avatar Jan 07 '21 21:01 Naktibalda

This issue is part of bigger issue that steps aren't displayed in unit tests.

Yeah, just noticing that --debug doesn't make any difference ;-) Why is this so? Let me guess: PHPUnit?

In any case, there should be a consistent way of adding comments to the tests overview in the CLI runner: I mean what wantTo() does (even if wantTo() is a misleading name for it). So (depending on what you answer at https://github.com/Codeception/Codeception/issues/6076#issuecomment-757389197) this might even be a new feature request.

I've never used tester object in my unit tests

So you how do you access the very class you're testing? I'm doing (Symfony):

protected function _before(): void
{
    $this->foo = $this->tester->grabService(Foo::class);
}

So the PHPUnit compatibility (as stated on https://codeception.com/docs/05-UnitTests: "Thus, any PHPUnit test can be added to a Codeception test suite and then executed.") is the reason for having the $this-> syntax instead of the $I-> syntax?

So the "formula" is?:

Codeception Unit = PHPUnit + Modules (e.g. database access, Symfony Services)

ThomasLandauer avatar Jan 10 '21 00:01 ThomasLandauer

If the tests use database and Symfony services they really aren't unit tests. I usually put tests that are testing database integration to db suite, because I don't want database initialisation and clean up after each real unit test.

So you how do you access the very class you're testing?

Unit test instantiates class under test and all its dependencies.

// dependencies
$bar = $this->createMock(Bar::class);
// Class under test
$foo = new Foo($bar);
// Test
$this->assertTrue($foo->baz());

Naktibalda avatar Jan 10 '21 08:01 Naktibalda

As explained in #6076 wantTo is a legacy method that should be used solely for Cept scenarios.

There is no point to make it work in Test format.

Naktibalda avatar Dec 29 '22 15:12 Naktibalda