Assert clarity
Posted: Fri Jul 29, 2005 8:59 pm
I have a few test cases where I feel the assertions lack clarity.
I'm checking for the existence of certain keys in a dictionary. It is aleady guarenteed that if the key exists its value is non-false; and that the dictionairy will return false if the key doesn't exist.
I've currently coded these assertions as
However, an "assertNotFalse" would probably indicate the intention better. Of course there is no such assertion and I don't think it would really be worth adding it via a local subclass of UnitTestCase. Perhaps
It just feels a little funny to use notEquals with false (or true) as one of expected values....
I could write it as
but that would be adding the geyKeys() purely to support easier testing -- there isn't a use-case demand for getKeys yet.
I guess the other option would be to use assertEquals with the actual returned value. However the returned values are slightly brittled and will likely have a fair bit of tweaking at the whitespace level that would be hard to properly right a regexp for.
Any other thoughts?
I'm checking for the existence of certain keys in a dictionary. It is aleady guarenteed that if the key exists its value is non-false; and that the dictionairy will return false if the key doesn't exist.
I've currently coded these assertions as
Code: Select all
$this->assertTrue($this->pb->getQuery("Key Name"));Code: Select all
assertNotEqual(false,$this->pb->getQuery("Key Name"));I could write it as
Code: Select all
$this->assertTrue(in_array("Key Name",$this->pb->getKeys()))I guess the other option would be to use assertEquals with the actual returned value. However the returned values are slightly brittled and will likely have a fair bit of tweaking at the whitespace level that would be hard to properly right a regexp for.
Any other thoughts?