Discussion of testing theory and practice, including methodologies (such as TDD, BDD, DDD, Agile, XP) and software - anything to do with testing goes here. (Formerly "The Testing Side of Development")
require_once 'PHPUnit/Framework/TestCase.php';
class TestOfStuff extends PHPUnit_Framework_TestCase
{
public function testSucess()
{
$this->assertEqual(1 + 2, 3);
$this->assertTrue(true);
$this->assertFalse(false);
$this->assertNull(null);
}
public function testFailure()
{
$this->assertEqual(1 + 2, 4);
$this->assertTrue(false);
$this->assertFalse(true);
$this->assertNull(1);
}
public function testFail()
{
$this->fail('Doh!');
}
public function testPass()
{
$this->pass();
}
public function testSkip()
{
$this->markTestSkipped('Skippy');
}
public function testIncomplete()
{
$this->markTestIncomplete('Incompletely Convincing');
}
}
$test = new TestOfStuff();
$result = new PHPUnit_Framework_TestResult();
$test->run($result);
And despite reading virtually everything in the almost entirely irrelevent, PHPUnit Pocket Guide I've still no idea how I actually run this test and get HTML output. Is there no HtmlReporter in PHPUnit?
Warning: Missing argument 2 for PHPUnit_Framework_Error::__construct(), called in /osis/lib/code/php/PHPUnit/Framework/TestCase.php on line 284 and defined in /osis/lib/code/php/PHPUnit/Framework/Error.php on line 79
Warning: Missing argument 3 for PHPUnit_Framework_Error::__construct(), called in /osis/lib/code/php/PHPUnit/Framework/TestCase.php on line 284 and defined in /osis/lib/code/php/PHPUnit/Framework/Error.php on line 79
Warning: Missing argument 4 for PHPUnit_Framework_Error::__construct(), called in /osis/lib/code/php/PHPUnit/Framework/TestCase.php on line 284 and defined in /osis/lib/code/php/PHPUnit/Framework/Error.php on line 79
Warning: Missing argument 5 for PHPUnit_Framework_Error::__construct(), called in /osis/lib/code/php/PHPUnit/Framework/TestCase.php on line 284 and defined in /osis/lib/code/php/PHPUnit/Framework/Error.php on line 79
Notice: Undefined variable: code in /osis/lib/code/php/PHPUnit/Framework/Error.php on line 81
Notice: Undefined variable: file in /osis/lib/code/php/PHPUnit/Framework/Error.php on line 83
Notice: Undefined variable: line in /osis/lib/code/php/PHPUnit/Framework/Error.php on line 84
Notice: Undefined variable: trace in /osis/lib/code/php/PHPUnit/Framework/Error.php on line 85
$test = new TestOfStuff();
$result = new PHPUnit_Framework_TestResult();
$test->run($result);
Shouldn't be triggering loads of errors should it?
I'm supposed to be able to get data of that $result object:
PHPUnit Pocket Guide wrote:void addError(PHPUnit_Framework_Test $test, Exception $e) Record that running $test caused $e to be thrown unexpectedly.
void addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e) Record that running $test caused $e to be thrown unexpectedly.
PHPUnit_Framework_TestFailure[] errors() Return the errors recorded.
PHPUnit_Framework_TestFailure[] failures() Return the failures recorded.
PHPUnit_Framework_TestFailure[] notImplemented() Return the incomplete test cases recorded.
int errorCount() Return the number of errors.
int failureCount() Return the number of failures.
int notImplementedCount() Return the number of incomplete test cases.
int count() Return the total number of test cases run.
Boolean wasSuccessfull() Return whether or not all tests ran successfully.
Boolean allCompletlyImplemented() Return whether or not all tests were completely implemented.
void collectCodeCoverageInformation(Boolean $flag) Enables or disables the collection of Code Coverage information.
Array getCodeCoverageInformation() Return the code coverage information collected.
Considering most of us appear to prefer SimpleTest around here.. that may not be a horrible idea, although it would be nice to have a few people versed in PHPUnit around for balance's sake.
Shame most of what I read about it sounded really cool, the PHP 5 support and all. No HTML Reporter == No point. If I knew my way about it I would probably write one myself but I don't and thus I can't justify the time it would take.