Tuesday, November 2, 2010

Subclassing TestSuite: put a class "BetterTestSuite" between MyGroupTest and TestSuite does not work?

Hi everybody

I'm having the following test group:

class MyGroupTest extends TestSuite {
function __construct() {
TestManager::addTestFile($this,
APP_TEST_CASES.DS.'views'.DS.'applications'.DS.'bla1.test.php');
TestManager::addTestFile($this,
APP_TEST_CASES.DS.'views'.DS.'applications'.DS.'bla2.test.php');
}
}

Works like a charm. So I wanted to refactor this a bit:

class MyGroupTest extends TestSuite {
var $tests = array('bla1', 'bla2');

function __construct() {
foreach($this->tests as $test) {
TestManager::addTestFile($this,
APP_TEST_CASES.DS.'views'.DS.'applications'.DS.$test.'.test.php');
}
}
}

Works like a charm. But now I wanted to put the constructor into its
own class, so I can subclass any other group test from it:

class BetterTestSuite extends TestSuite {
var $tests = array();

function __construct() {
foreach($this->tests as $test) {
TestManager::addTestFile($this,
APP_TEST_CASES.DS.'views'.DS.'applications'.DS.$test.'.test.php');
}
}
}

class MyGroupTest extends BetterTestSuite {
var $tests = array('bla1', 'bla2');
}

Does *not* work. The result is always:

0/0 test cases complete: 0 passes, 0 fails and 0 exceptions.

Anybody knows why? No idea what's the problem here... I guess it has
something to do with how SimpleTest handles groups and stuff (maybe it
depends on that the tests are really put into TestCase and not into a
subclass of TestCase or something)... But I just don't find the
reason...

Thanks a lot for help!
Josh

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: