Created
May 17, 2012 19:53
-
-
Save testingbot/2721226 to your computer and use it in GitHub Desktop.
phpunit custom junit logger
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
phpunit.xml | |
------------------ | |
<?xml version="1.0" encoding="UTF-8"?> | |
<phpunit | |
backupGlobals="false" | |
colors="true"> | |
<testsuites> | |
<testsuite name="PHPUnitee"> | |
<file>SimpleTest.php</file> | |
</testsuite> | |
</testsuites> | |
<listeners> | |
<listener class="MyListener" file="MyListener.php"> | |
<arguments> | |
<string>results.xml</string> | |
</arguments> | |
</listener> | |
</listeners> | |
</phpunit> | |
-------------------------------- | |
SimpleTest.php | |
------------------------------- | |
<?php | |
class SimpleTest extends PHPUnit_Extensions_TestingBotTestCase | |
{ | |
public static $browsers = array( | |
array( | |
'name' => 'FireFox', | |
'browser' => 'firefox', | |
'platform' => 'WINDOWS', | |
'browserVersion' => '12', | |
'timeout' => 1000, | |
) | |
); | |
protected function setUp() | |
{ | |
$this->setHost('hub.testingbot.com'); | |
$this->setPort(4444); | |
$this->setBrowserUrl('http://www.google.com/'); | |
$this->setDesiredCapabilities(array( | |
'screenrecorder' => false, | |
)); | |
} | |
public function testTitle() | |
{ | |
$this->open('/'); | |
$this->assertTitle('bla2'); | |
} | |
} | |
?> | |
------------------------------- | |
MyListener | |
------------------------------- | |
<?php | |
class MyListener extends PHPUnit_Util_Log_JUnit implements PHPUnit_Framework_TestListener | |
{ | |
/** | |
* A test ended. | |
* | |
* @param PHPUnit_Framework_Test $test | |
* @param float $time | |
*/ | |
public function endTest(PHPUnit_Framework_Test $test, $time) | |
{ | |
if (!$test instanceof PHPUnit_Framework_Warning) { | |
if ($this->attachCurrentTestCase) { | |
if ($test instanceof PHPUnit_Framework_TestCase) { | |
$numAssertions = $test->getNumAssertions(); | |
$this->testSuiteAssertions[$this->testSuiteLevel] += $numAssertions; | |
$this->currentTestCase->setAttribute( | |
'assertions', $numAssertions | |
); | |
} | |
$this->currentTestCase->setAttribute( | |
'time', sprintf('%F', $time) | |
); | |
// add custom timestamp | |
$this->currentTestCase->setAttribute( | |
'timestamp', time() | |
); | |
$this->testSuites[$this->testSuiteLevel]->appendChild( | |
$this->currentTestCase | |
); | |
$this->testSuiteTests[$this->testSuiteLevel]++; | |
$this->testSuiteTimes[$this->testSuiteLevel] += $time; | |
} | |
} | |
$this->attachCurrentTestCase = TRUE; | |
$this->currentTestCase = NULL; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment