Friday, 15 May 2015

php - PHPUnit: Proper pattern for failing on missing tests? -



php - PHPUnit: Proper pattern for failing on missing tests? -

i have looked native solution, phpunit fail when encounters method in target class/object not have defined test for. have, far, not been able find way this.

in meantime, solution have rolled myself include next test @ top of of test classes:

public function test_methodcoverage () { $class = new reflectionclass($this->_classname); $methods = $class->getmethods(); foreach ( $methods $v ) { $this->asserttrue( method_exists( $this, 'test'.ucfirst($v->name) ), 'test method '. $v->name .' not exist' ); } }

note: $this->_classname property created in setup() contains target class path.

i wondering, there more appropriate/native way accomplish functionality without doing manually?

thanks

your solution if want methods have test. private methods must tested undirectly should utilize code coverage tools analyze methods tested , methods not tested.

use of phpunit code coverabe tool simple. example:

phpunit --coverage-html ./report bankaccounttest

source: http://phpunit.de/manual/3.7/en/code-coverage-analysis.html

php unit-testing phpunit

No comments:

Post a Comment