Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output total time taken by slow tests #85

Open
bdsl opened this issue May 13, 2021 · 2 comments
Open

Output total time taken by slow tests #85

bdsl opened this issue May 13, 2021 · 2 comments

Comments

@bdsl
Copy link

bdsl commented May 13, 2021

I think it would be really handy to see the total time taken by all the slow tests, to get a good idea of how useful it would be to speed them up or move them out of the main test suite.

I haven't looked at the implementation of phpunit-speedtrap but if this is a desired feature I think I'd be happy to have a go at implementing it.

@johnkary
Copy link
Owner

@bdsl That's a good idea. I would accept a PR for that feature if someone would like to implement it.

It should be fairly easy. If I were writing it, the endTest() method has access to all test execution times in milliseconds. Accumulate each test's execution times, then in a new output method like renderStats() calculate the total slow/fast times by partitioning the collected times, summing them, and formatting for output.

PHPUnit outputs the total execution time in seconds. That makes sense for this feature because many slow tests together will likely exceed 1 second.

Maybe an output like this when slow tests are found:

$ ./vendor/bin/phpunit --group=slow
PHPUnit 8.5.14 by Sebastian Bergmann and contributors.

..........                                                                 10 / 10 (100%)
You should really speed up these slow tests (>500ms)...
 1. 6805ms to run JohnKary\\PHPUnit\\Listener\\Tests\\SomeSlowTest::testWithDataProvider with data set "Rock"
 2. 1000ms to run JohnKary\\PHPUnit\\Listener\\Tests\\SomeSlowTest::testWithDataProvider with data set "Chalk"
 3. 695ms to run JohnKary\\PHPUnit\\Listener\\Tests\\SomeSlowTest::testWithDataProvider with data set "Jayhawk"

Fast Tests: 0.5 seconds (5.56%)
Slow Tests: 8.5 seconds (94.44%)

Time 9.0 seconds, Memory: 8.00 MB

If no slow tests are detected output Slow Tests: 0 seconds (0%) so the output remains consistent for anyone programmatically parsing it.

I'm open to any suggestions. The above is proposed as a starting point.

@bdsl
Copy link
Author

bdsl commented May 21, 2021

Thanks @johnkary - sorry for radio silence. I'll try and give that a go this weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants