如果您正在测试一个像下面那样的计数函数,那么在一个函数中为函数测试多个事情,是否认为是“正确”或“错误”,而不是每个测试都具有测试函数?在单个测试中断言多个条件,还是分成多个测试?
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();
}
如果我理解正确,那么您会说它更容易,但在一个测试用例中拥有更多场景的“正确”程度却更低。 如果这意味着您将多个场景放入一个测试用例中,因为制作多个测试用例的工作太多了,我会说:抽象它,让它更容易,更干燥来制作另一个场景。 测试也是编程imho和应该做或多或少相同的原则,如DRY。 – 2010-01-31 21:17:15