johnkary / phpunit-speedtrap

Reports on slow-running tests in your PHPUnit test suite
MIT License
782 stars 62 forks source link

Display @dataProvider parameters #61

Closed lukepass closed 5 years ago

lukepass commented 5 years ago

Hello, when using tests with parameters it could be useful to actually show the parameters' values.

You should really fix these slow tests (>50ms)...
 1. 309ms to run Tests\AppBundle\Admin\AdminTest:testAdminRoutes with data set #0
 2. 276ms to run Tests\AppBundle\Admin\AdminTest:testAdminRoutes with data set #57
 3. 165ms to run Tests\AppBundle\Admin\AdminTest:testAdminRoutes with data set #1
 4. 122ms to run Tests\AppBundle\Admin\AdminTest:testAdminRoutes with data set #34
 5. 121ms to run Tests\AppBundle\Admin\AdminTest:testAdminRoutes with data set #54

Thanks!

johnkary commented 5 years ago

@lukepass That's a great idea! If anyone can add this feature let's do it.

willemstuursma commented 5 years ago

Not necessary. You can set keys as names for the dataproviders that will also make it clearer which tests ran when using PHPUnit:

public function dpSomeDataForTests(): array {
    return [
        "condition 1" => ["param1", "param2"],
        "condition 2" => ["param1", "param3"],
    ];
}
johnkary commented 5 years ago

@lukepass As @willemstuursma showed above, if you add a string before each @dataProvider entry it will output in the slowness threshold report. The PHPUnit documentation has great examples here: https://phpunit.readthedocs.io/en/8.3/writing-tests-for-phpunit.html#writing-tests-for-phpunit-data-providers-examples-datatest1-php

@willemstuursma Thank you for helping with the example.

Thanks for making this suggestion! 🚀