If you were testing a count function like the one below, is it considered to be 'right' or 'wrong' to test multiple things for the function in one function vs having a test function for each of the tests?
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();
}
you can have multiple asserts on the same object. they will usually be the same concept being tested.
As long as you clearly label assertions there is no problem in using multiple.
“One assertion per test” is a wise rule to keep in mind, because it helps you have tests that fail for a specific reason, and drives you to focus on a specific behavior at a time.
You should have multiple test functions, where each tests its own condition. That way it is easier to spot a failure without debugging.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With