laravel 4 - How to reuse PHPUnit functions -
i want reuse of phpunit functions calling them instead of repeating them in unit tests, such example:
public function testcontent() { $this->assertnotempty($this->response, $this->message); }
if place under tests/testcase.php, runs unit tests.
where right place put or how done? btw, using on laravel 4.
apparently, problem not re-use tests, tests beeing called when it's not expected.
so, have in mind: method name starting "test" (testfoo, testbar) in existing class considered test.
so if have classes a, b , c this
class extends \phpunit_framework_testcase { public function testfoo() {...} public function testbar() {...} } class b extends { public function testbaz() {...} } class c extends { public function testquz() {...} }
you have 8 tests: a::testfoo(), a::testbar(), b::testfoo(), b::testbar(), b::testbaz(), c::testfoo(), c::testbar(), c::testquz().
it's not trying make. may want have testfoo , testbar in classes b , c, not a. in case, have declare abstract class.
abstract class extends \phpunit_framework_testcase { public function testfoo() {...} public function testbar() {...} } class b extends { public function testbaz() {...} } class c extends { public function testquz() {...} }
now have 6 tests: b::testfoo(), b::testbar(), b::testbaz(), c::testfoo(), c::testbar(), c::testquz().
maybe, it's need, maybe not. maybe, want have testfoo() , testbar() in some inherited classes, not of them.
in case, make assertions in parent class instead of tests.
abstract class extends \phpunit_framework_testcase { public function assertfoo() { ... } public function assertbar() { ... } } class b extends { public function testfoo() { $this->assertfoo(); ...} public function testbaz() {...} } class c extends { public function testbar() { $this->assertbar(); ...} public function testquz() {...} }
now, have 4 tests: b::testfoo(), b::testbaz, c::testbar(), c::testquz()
Comments
Post a Comment