|
Database testing strategy in build
[
vmassol
]
Applying a working build strategy for testing against a database is not easy. It depends on the complexity of the database model, it depends on the size of the teams. However, I've found that the strategy described below is the one that has worked the best for the projects I have been involved in:
On the other hand, here are strategies that have not been working so well for me in the past:
Is that also your experience? I like in a world where the dba is so retarded they don't want to let developers have the rights to create schemas in teh development database!!! we so urgently need what you describe yet some silly person stands between us and the database. we need to support two, maybe three versions of the database schema also. the solution offered is for dba to maintain two or three schemas per developer to use as private areas for unit testing! i kid not. instead of just letting us execute sql script or dbunit xml into own private schema. but thanks for your blog vincent yet another data point to nail in to this stupid coffin that confines us. --frustrated, February 16, 2004 12:41 PM
Great and timely entry! http://www.martinfowler.com/articles/evodb.html I saw Pramod give this talk at our local JUG last year, it was really good. I have been following the agileDatabases list at yahoogroups also. It may be the next level of what you're describing. I agree with you that it is extremely difficult. Our challenge right now is our programmer tests ( integration included ) run on each commit. It is really slow, 90 minute builds for 50+ projects, the majority of the time spent on these integration type tests. I'm attempting to try maven as a build solution, and at the same time separate into projects the code+programmer tests, integration programmer tests, and customer tests. I have a theory that the integration tests are happening because the code isn't written with testing in mind ( ala TDD ). That pushes developers to test-last and farther away from the code which leads to the integration-type tests. We have the same issues with other external systems, like file shares, ldap, remote services, etc. --Jeff Brekke, February 16, 2004 02:39 PM
This is something that we're sorting out at the moment on my current project and one of the decisions is whether to implement the stuff that sets up the database schema/data as a script (not portable but easy) or as Java classes (can run on the UNIX boxes too). In the short term we're probably going for a script but will migrate this to a Java class in the future. Any thoughts? --Simon Brown, February 16, 2004 04:46 PM
I have personally experienced all of the issues that you pointed out with regards to testing against a live database. Normally I used some of the strategies to avoid the necessity. That was until I consulted in an environment where I had no choice but to work with the live database. The way the problem had been addressed was to just avoid testing altogether. This was not an option. What had sort of worked for me in the past dealing with this sort of environment was to put data into the database in the setup method, and then remove it in the teardown. The only issue is that multiple people could not run the tests at the same time for fear of having conflicting primary key entries (I have not dbunit, but I think it might have solved that?) This was not going to work because the database we were dealing with was very trigger happy. The final solution that has worked well for the last 6 months or so was to wrap each test in its own transaction, finally rolling back the transaction in the tear down. This worked very well, and even played nice with Hibernate since Hibernate just piggy backs off of an existing transaction if one exists. I put up a version of the code on my blog. Has anyone else done this, or see issues that we may not have encountered yet? If so please let me know. My mail is on my site, or just comment here or there. Its a topic that definitely interests me. --Cobbie Behrend, February 16, 2004 08:27 PM
I see other drawbacks with tests wrapped in their own transaction. --Pascal Thivent, February 16, 2004 10:59 PM
Hi Jeff, [snip] > http://www.martinfowler.com/articles/evodb.html I hadn't read that link. I've skimmed through it and it looks great. I'll now read it in details. I think you're right and it might be the next level of what I'm describing. Thanks for the link. [snip] > I agree with you that it is extremely difficult. Our challenge right now That’s cool. We're using Maven too (we have about 100+ projects and our build takes about 1 hour - We are really missing tests though - that's the reason it's not taking longer...). People here have mixed IUT and pure unit tests. I'd also like make a local project build on each commit (actually I was going to blog about this) and we'll need to separate IUT from pure unit tests for that. > I have a theory that the integration tests are happening because the code I don't quite agree :-) I believe you're right that writing a la TDD will remove integration test needs but you'll still need to test the integration/functional parts. So it's just pushing the problem a bit further. But I agree that all in all it should reduce the time the whole suite of tests takes. With Cactus2 (http://blogs.codehaus.org/people/vmassol/archives/000520_cactus_v2_architecture_proposal.html), I'm trying to introduce a new type of test: white box functional testing... ;-). It's a bit what I had started a year ago with PatternTesting (http://patterntesting.sourceforge.net/). The idea is to run functional tests but still be able to see what's going on in the application by putting probes inside the code. You're also able to perform IUT (a la Cactus) by redirecting the flow of execution to wherever you wish. This is useful for testing tricky parts that are communicating with the server. For example, say you wish to verify that your code behaves correctly when there is a container transaction rollback. Don’t know if people will find it useful or not but there's only one way to find out... ;- [snip] --VincentMassol, February 17, 2004 08:40 AM
1) SQL-Script vs. Java code for DB setup: We have used a variant of the ObjectMother-Pattern to create persistent test data. This was more convenient for complex object models, compared to writing SQL-Scripts by hand. A lot of foreign key relationships had to be coded by hand in SQL-Scripts and were done automatically if you just persist your Java objects. 2) Developer local databases and DBA trouble: Greetings, --Malte Finsterwalder, February 18, 2004 09:20 AM
Challenging Pascal's proposal: DbUnit files have one inconvenient, they require DB structure - so DB development ! - to be stable; because refactoring dbunit files when you change the structure of your database is tricky, nearly impossible. Whereas refactoring directly "data" at the same time you change the structure is more easy. And there are no reason why java developers could develop progressively, refactore their code and db developers not ! However I agree using a live database is painfull to "version control". Unless someone spend some time on a system to manage dbunit files... --Dominique, March 15, 2004 10:15 AM
I have a detailed article posted at http://www.agiledata.org/essays/databaseTesting.html which you might find interesting. It overviews how you go about testing a relational database. The interesting point is that you need to be concerned about both interface testing as well as internal testing. Most people just focus on interface testing. - Scott --Scott Ambler, December 11, 2006 12:16 AM
We use Scriptella ETL (http://scriptella.javaforge.com) to setup a database for both production deployment and in-memory testing. As a bonus you get an embeddable easy-to-use ETL tool with support for XML, CSV and LDIF. --ejboy, February 5, 2007 05:40 PM
Post a comment
|