testOfStuff() {
$stuff_dao->insertStuff($name, $email);
$some_data = $stuff_dao->getStuffByEmail($email);
// assertions based on data returned from DAO getStuffByEmail() call...
}
So in this case we are verifying that "stuff" data was inserted properly by making a getStuffByEmail() call to the same StuffDAO.
I would argue that we should avoid using DAO calls to verify data insertion in a test. I suggest a better test example would be something like:
testOfStuff() {
$stuff_dao->insertStuff($name, $email);
$stmt = $pdo->query( "select * from stuff where email = ' . $email);
$data = $stmt->fetch();
// assertions based on $data...
}
this way we keep the tests as discreet as possible and avoid relying on other functionality to test our specific insert code.
-Mark
--
You received this message because you are subscribed to the Google Groups "ThinkTank App" group.
To post to this group, send email to thinkt...@googlegroups.com.
To unsubscribe from this group, send email to thinktankapp...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/thinktankapp?hl=en.
Here is a simple example where this could be problematic:
- You hack up some "get" code that returns a bool=false where is should be returning a true, but your test doesn't catch the problem.
- You then add an "insert" call that is failing to insert proper data to return a bool=false value, but the "get" returns false so you think your test is passing properly because of the bad "get" method.
- The dependance of the "insert" test on the bad "get" code now introduces two bugs instead of one.
Our Mysql DAO tests really should make calls directly to the db to verify insert/update data to reduce the risk of other DAO code mudding the test results, and to verify with better certainty that our persistence code is functioning as designed. It is basically the inverse of how we set up data to test our "get" code.
This will also help keep fail messages directed to the actual tests that are failing, so instead of getting a list of fails for the "get", "insert" and "update" tests you only get fails for "get" code that is actually failing.
-m
Yes it's a valid point, and I agree (even though I have done it the
"lazy way" so far).
There are dozens of books written about testing best practices, and I
don't want to rewrite those. But now that we're getting disciplined
about testing, it's worth documenting the things I'll look for on pull
requests. I've started a developer guide including this point and one
other:
http://wiki.github.com/ginatrapani/thinktank/developer-guide-how-to-write-great-unit-tests