DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Coding
  3. Frameworks
  4. The Joy of DBUnit

The Joy of DBUnit

Andrew Spencer user avatar by
Andrew Spencer
·
Jan. 13, 11 · Interview
Like (1)
Save
Tweet
Share
1.35K Views

Join the DZone community and get the full member experience.

Join For Free

I like DBUnit. Well, I dislike using it, but that’s because I dislike writing persistence tests. I’d hate them a lot more without it.

I like it not only because it turns a dreaded chore into a mildly unpleasant one, but for how easy it is to extend and modify. Virtually everything in DBUnit, at least everything you might need to customise, is designed in what I think of as the Spring style: a combination of interfaces, abstract implementations and concrete implementations. The method and constructor parameters expect and return interfaces, so you can plug in any implementation you like, including your own. If you do want to implement your own version, there’s an abstract base class providing basic common features that you can rely on. And to make it easy to get started, there are already concrete implementations covering at least 95% of potential use cases. These help you in two ways: you can use them off-the-shelf and they just work, and when you need, you can model your own implementations on them.

The danger with the Spring style is that defining everything in terms of interfaces makes it, paradoxically, difficult to learn at first. I had that problem with Spring Batch. It’s so modular that you’re never quite sure how it all fits together. The docs perpetuate this implementation-agnostic confusion: each component’s interactions are described abstractly, because the author doesn’t know which implementation you will really choose to supply. I don’t have a problem with abstraction, but I need to start from concrete examples. After you’ve built your first batch, you have your marks, you have a nominal case in mind and everything is just variations on that. But at the beginning, it’s confusing.

DBUnit doesn’t have that problem, perhaps because the number of potential use cases is far smaller, but I think also because the documentation takes, as its starting point, a nominal case using concrete classes, and then describes variants thereof.

DBUnit isn’t perfect by any means. Not everyone finds it as easy to use as they’d like (take that infuriating issue with resolving DTDs, for instance), and there’s some pretty crufty code in its entrails, if you go digging. But I like it all the better for that. When I look at the source code of most Spring components, I could never imagine writing something that myself. When I read DBUnit’s source code, I’m more likely to think, “Hey, I could write something like that.” For that reason, DBUnit makes a better ambassador for the Spring style than does Spring itself. It shows that you don’t need to be a magician to write a useful and extensible component. You just need to care.

Implementation Spring Framework Joy (programming language) Interface (computing) IT Testing Interaction

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Solving the Kubernetes Security Puzzle
  • A Gentle Introduction to Kubernetes
  • Testing Level Dynamics: Achieving Confidence From Testing
  • 11 Observability Tools You Should Know

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: