-
Notifications
You must be signed in to change notification settings - Fork 62
Show total slow and fast test time in output #87
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
Open
bdsl
wants to merge
5
commits into
johnkary:master
Choose a base branch
from
bdsl:show-total-slow-test-time
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
59da4b7
Add test for basic output from one slow test
bdsl cfdc51a
Add test for reporting on results from two tests
bdsl fead3cd
Output stats on total of fast and slow tests
bdsl adb29b4
Add test for combination of slow and fast tests
bdsl 5aded4e
Use distinct speed threshold in test to avoid coincidence with defaul…
bdsl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/phpunit.xml | ||
/vendor | ||
/composer.lock | ||
/.phpunit.result.cache |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JohnKary\PHPUnit\Listener\Tests; | ||
|
||
use JohnKary\PHPUnit\Listener\SpeedTrapListener; | ||
use PHPUnit\Framework\TestCase; | ||
use PHPUnit\Framework\TestListener; | ||
use PHPUnit\Framework\TestSuite; | ||
|
||
final class SpeedTrapListenerTest extends TestCase | ||
{ | ||
/** @var TestListener */ | ||
private $speedTrapListener; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->speedTrapListener = new SpeedTrapListener(['slowThreshold' => 444]); | ||
} | ||
|
||
public function testItPrintsSpeedData(): void | ||
{ | ||
$testSuite = new TestSuite(); | ||
$this->speedTrapListener->startTestSuite($testSuite); | ||
$this->speedTrapListener->startTest($this); | ||
|
||
$this->speedTrapListener->endTest($this, 1 /*second*/); | ||
|
||
$output = $this->captureOutput(function () use ($testSuite) { | ||
$this->speedTrapListener->endTestSuite($testSuite); | ||
}); | ||
|
||
self::assertSame( | ||
' | ||
|
||
You should really speed up these slow tests (>444ms)... | ||
1. 1000ms to run JohnKary\\\\PHPUnit\\\\Listener\\\\Tests\\\\SpeedTrapListenerTest::testItPrintsSpeedData | ||
|
||
Fast tests: 0.0 seconds (0.00%) | ||
Slow tests: 1.0 seconds (100.00%) | ||
' | ||
, | ||
$output | ||
); | ||
} | ||
|
||
|
||
public function testItDisplaysTotalSlowTestTime(): void | ||
{ | ||
$testSuite = new TestSuite(); | ||
|
||
$test1 = new self('test one'); | ||
$test2 = new self('test two'); | ||
|
||
$this->speedTrapListener->startTestSuite($testSuite); | ||
$this->speedTrapListener->startTest($test1); | ||
$this->speedTrapListener->endTest($test1, 2); | ||
|
||
$this->speedTrapListener->startTest($test2); | ||
$this->speedTrapListener->endTest($test2, 1.5); | ||
|
||
$output = $this->captureOutput(function () use ($testSuite) { | ||
$this->speedTrapListener->endTestSuite($testSuite); | ||
}); | ||
|
||
self::assertSame( | ||
' | ||
|
||
You should really speed up these slow tests (>444ms)... | ||
1. 2000ms to run JohnKary\\\\PHPUnit\\\\Listener\\\\Tests\\\\SpeedTrapListenerTest::test one | ||
2. 1500ms to run JohnKary\\\\PHPUnit\\\\Listener\\\\Tests\\\\SpeedTrapListenerTest::test two | ||
|
||
Fast tests: 0.0 seconds (0.00%) | ||
Slow tests: 3.5 seconds (100.00%) | ||
' | ||
, | ||
$output | ||
); | ||
} | ||
|
||
public function testItDisplaysTotalSlowAndFastTestTime(): void | ||
{ | ||
$testSuite = new TestSuite(); | ||
|
||
$test1 = new self('slow test one'); | ||
$test2 = new self('slow test two'); | ||
|
||
$fastTest = new self('this one is fast'); | ||
|
||
$this->speedTrapListener->startTestSuite($testSuite); | ||
$this->speedTrapListener->startTest($test1); | ||
$this->speedTrapListener->endTest($test1, 2 /* duration in seconds */); | ||
|
||
|
||
$this->speedTrapListener->startTest($test2); | ||
$this->speedTrapListener->endTest($test2, 1.5); | ||
|
||
$this->speedTrapListener->startTest($fastTest); | ||
$this->speedTrapListener->endTest($fastTest, 0.4); | ||
|
||
$output = $this->captureOutput(function () use ($testSuite) { | ||
$this->speedTrapListener->endTestSuite($testSuite); | ||
}); | ||
|
||
self::assertSame( | ||
' | ||
|
||
You should really speed up these slow tests (>444ms)... | ||
1. 2000ms to run JohnKary\\\\PHPUnit\\\\Listener\\\\Tests\\\\SpeedTrapListenerTest::slow test one | ||
2. 1500ms to run JohnKary\\\\PHPUnit\\\\Listener\\\\Tests\\\\SpeedTrapListenerTest::slow test two | ||
|
||
Fast tests: 0.4 seconds (10.26%) | ||
Slow tests: 3.5 seconds (89.74%) | ||
' | ||
, | ||
$output | ||
); | ||
|
||
self::assertEqualsWithDelta(10.26, 100*0.4/(0.4+3.5), 0.01); | ||
self::assertEqualsWithDelta(89.74, 100*3.5/(0.4+3.5), 0.01); | ||
} | ||
|
||
private function captureOutput(\Closure $closure): string | ||
{ | ||
ob_start(); | ||
$closure(); | ||
return ob_get_clean(); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to keep the output minimal and optimized to it's purpose :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. I'll adjust it in a couple of days when I some time, or if you prefer feel free to merge and edit. Thanks.