I have a function that should progress on specific model status and throw exception on other statuses. Writing unit tests for that function, I made private function that takes status as the argument and performs the test and multiple public test functions, all that each of them do is call that private function with different status.
private function testInvalidUserStatus ($status) {
//perform the test
}
public function testExceptionThrownOnUserWithXStatus () {
$this->testInvalidUserStatus(UserStatuses::X);
}
public function testExceptionThrownOnUserWithYStatus () {
$this->testInvalidUserStatus(UserStatuses::Y);
}
public function testExceptionThrownOnUserWithZStatus () {
$this->testInvalidUserStatus(UserStatuses::Z);
}
The problem with this approach is, that if some new status is added to user and I forget to change behaviour in this particular tested function, the tests give me false positive as I have no information that it is not tested against this new status. Firstly I came up with running the test in loop through array of statuses, but test ended after first iteration. Is there some possiblity, to at least have some information, that the function isn't tested against some particular status?
Aucun commentaire:
Enregistrer un commentaire