how to test specific database rows

Discussion of testing theory and practice, including methodologies (such as TDD, BDD, DDD, Agile, XP) and software - anything to do with testing goes here. (Formerly "The Testing Side of Development")

Moderator: General Moderators

Post Reply
Forum Commoner
Posts: 73
Joined: Mon Sep 27, 2010 3:26 pm

how to test specific database rows

Post by kc11 »


I am working on testing a project, using database input. My application takes as input , individual records ( table rows ) from a mysql table. As I've tested, I have gradually debugged the program so that almost all the records result in correct output, but there are still a few that are causing problems. I would to select ONLY the individual records, that are still causing problems for input, or else suspend the program when one of the records of concern is being taken as input. I'd like to do this if possible without hard coding

Is there a way to set a watch in XDEBUG so that the program is run until a certain record is reached , when it can break, allowing me to step through the code.

Another way I've thought of doing this is somehow to sort the mysql table ( in phpmyadmin? ) so that the problem records would be taken as the first input,

Are either of these possible, or is there a better way?

Thanks in advance,

User avatar
Posts: 6425
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: how to test specific database rows

Post by Celauran »

I advise against using data from a database to populate your tests as a change in any of these rows can cause tests to begin failing for no discernible reason. Sure, it might be more work to transform these into datasets for DBUnit or into data providers for PHPUnit, but you will also end up with higher confidence in your tests.
User avatar
Site Administrator
Posts: 13595
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: how to test specific database rows

Post by Christopher »

Yes, if you are getting data from a database to test, you should be able to mock that data and run the tests reliably and in any order you want. Celauran's suggestion of datasets or data providers is a good direction.
User avatar
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: how to test specific database rows

Post by VladSun »

+1 for both oppionions above

Your application should instatinate several classes and one of them is the "DB repository" - i.e. a so-so dummy class responsible only for fetching DB data. The business logic is applied to the data received from this class.

For the "DB" class use DBUnit tests (according to our company terminology these are the "Integration tests") to fully test SQL/ORM etc. code that lies outside your business domain boundaries.

And for the business classes - provide a mocked data and test "DBless".
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply