On Mon, Jun 24, 2013 at 11:41 AM, Ayush Chaudhary ayushchd@gmail.comwrote:
Hi,
I was testing Tracker.class.php. There are a quite a few assertions related to database queries I might need to implement. I wanted to know what would be the best approach between using dummy queries and mocking the database interface class.
What I thought was to use dummy queries when the SQL query is a SELECT statement and the result of the query is being further used.
Please advice.
Thanks!
Ayush Chaudhary
Hi Ayush,
Dummy DBI and mocking has it's own advantages and choosing between them should be based on the case at hand. Dummy DBI would make it easy to add a common behavior for a query that is used in more than one test case where the expected output of all the tests are the same. On the other hand mocking would give you more control over the behavior. If different tests need to see the database interface return different results for the same query, you have no choice other than mocking.
Another situation where you cannot use dummy DBI is ascertaining the correctness of the queries generated. For example, in Node::getData() to test the correctness of the generated query you need to use mocking. In this case the solution would be to create a mock database interface which expected the correct query just once.