Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can PHP SimpleTest framework be configured to fail fast?

I'm new to the PHP SimpleTest framework, and I was surprised to see that a failed assertion doesn't halt the test method. In other words, this causes two failure messages in the test report:

function testFoo() {
    $this->assertTrue(true, 'first: %s');
    $this->assertTrue(false, 'second: %s');
    $this->assertTrue(false, 'third: %s');
}

Most of my unit testing experience is with JUnit and NUnit, and they both halt a test method as soon as the first assertion fails. Maybe I'm just used to that, but it seems like the extra failure messages will just be noise. It reminds me of old C compilers that would spew 50 errors because of a missing semicolon.

Can I configure SimpleTest to fail fast, or do I just have to live with a different style?

like image 397
Don Kirkby Avatar asked Jun 08 '26 18:06

Don Kirkby


1 Answers

You could extend/modify the Reporter class so it will exit() after a paintFail().
(No modification of the unittests required)

Or

The assert* functions return a boolean value, So for example:

 $this->assertTrue(false, 'second: %s') or return;

would end the current test function.

PS:
If you're using PHPUnit_TestCase class instead of UnitTestCase, the assert* functions won't return a boolean.

like image 167
Bob Fanger Avatar answered Jun 11 '26 06:06

Bob Fanger