在单个测试中断言多个条件,还是分成多个测试?

Geo*_*F67 5 php testing unit-testing correctness

如果您正在测试类似下面的计数函数,那么在一个函数中为函数测试多个东西而不是为每个测试都测试函数,它被认为是"正确"还是"错误"?

function testGetKeywordCount() {
    $tester = $this -> getDatabaseTester($this -> CompleteDataFile);
    $tester -> onSetUp();

    $KeywordID = 0;
    $this -> setExpectedException('InvalidArgumentException');
    $this -> keyword -> getKeywordCount($KeywordID,'Active');

    $KeywordID = 1;
    $this -> setExpectedException('InvalidArgumentException');
    $this -> keyword -> getKeywordCount($KeywordID,'InvalidStatus');

    $this -> assertEquals(1, $this -> keyword -> getKeywordCount($KeywordID,'Active'));

    $tester -> onTearDown();
}
Run Code Online (Sandbox Code Playgroud)

gro*_*ver 4

您应该有多个测试函数,每个函数都测试自己的条件。这样,无需调试就可以更轻松地发现故障。