Codeception / Codeception

Full-stack testing PHP framework
http://codeception.com
MIT License
4.75k stars 1.3k forks source link

Output messages don't make sense #6714

Closed neuberkauf closed 7 months ago

neuberkauf commented 7 months ago

What are you trying to achieve?

I'm probably overlooking something dumb, but searching around for this hasn't produced much help.

When running tests verbosely (-vv, -vvv), i want each assertion's output to read neatly, using the Constraint's self-describing toString(). For example:

public function _ (UnitTester $I)
{
    $I->assertThat(true, \PHPUnit\Framework\Assert::isTrue());
    $I->assertFalse(false);
}

i expect something like: I assert that true is true I assert false is false

What do you get instead?

The first one is especially off-putting. Why is it using the Constraint's FQN? I assert that true, "PHPUnit\\Framework\\Constraint\\IsTrue" I assert false false

Provide console output if related. Use -vvv mode for more details.


$ php vendor/bin/codecept run Unit TestCest:default -vvv

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

Tests.Unit Tests (1) ------------------------------------------------------- Modules: Asserts

TestCest: Default Signature: Tests\Unit\TestCest:default Test: tests/Unit/TestCest.php:default Scenario -- I assert that true,"PHPUnit\Framework\Constraint\IsTrue" I assert false false PASSED


Time: 00:00.513, Memory: 4.00 MB

OK (1 test, 2 assertions)

> Provide test source code if related

```php
/**
 * @test
 */
public function default(UnitTester $I)
{
    $I->assertThat(true, \PHPUnit\Framework\Assert::isTrue());
    $I->assertFalse(false);
}

Details

actor: UnitTester modules: enabled:

Naktibalda commented 7 months ago

This is how Codeception step works. It converts action name to words and appends all arguments. It looks much better when you use a module that was properly designed for Codeception:

I am on page "/about"
I click "button"
I see "some text"

I aggree that Asserts step output is ugly, but there is not much we can do short of rewriting Asserts module and/or Codeception.

assertThat is the only method that takes constraint as parameter, the output could be improved by modifying Step class to call toString - https://github.com/Codeception/Codeception/blob/7d754d1891316d8c525fdb8a0ad7811c5cb9f955/src/Codeception/Step.php#L169-L179

Generating step outputs from method names is one of the main Codeception ideas, I don't thing that it can be replaced with something similar to Constraint.

neuberkauf commented 7 months ago

i figured the Assert language is coming from the underlying PHPUnit. No big deal there.

Adjusting to handle Constraint objects would be fantastic. Seems like a simple thing if you'd like me to check out and submit a PR.

jtheuerkauf commented 7 months ago
$ php codecept run unit tests/unit/Codeception/StepTest.php

Codeception PHP Testing Framework v5.0.12 https://stand-with-ukraine.pp.ua
[Seed] 109444475

Unit Tests (12) ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
✔ StepTest: Multi byte text length is measured correctly(0.74s)
✔ StepTest: Single quoted string as argument(0.00s)
✔ StepTest: See uppercase text(0.00s)
✔ StepTest: Get arguments(0.15s)
✔ StepTest: Array as argument(0.00s)
✔ StepTest: No args(0.00s)
✔ StepTest: Constraint output(0.24s) * new *
✔ StepTest: Formatted output(0.02s)
✔ StepTest: See multi line string in single line(0.00s)
✔ StepTest: Am on url(0.00s)
✔ StepTest: Get html(0.00s)
✔ StepTest: Long arguments(0.02s)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Time: 00:05.290, Memory: 12.00 MB

OK (12 tests, 24 assertions)
neuberkauf commented 7 months ago

(Sorry for posting under two accounts... This one is my work account - i forgot to switch over.)