
DbUnit Review
- LGPL 2.1
- No paid edition
- Maven plugin and Ant task included
- Published on Maven Central
- Everything is free
- Jar targets Java 8
- JUnit 5/6 extension (JUnit 6 needs Java 17)
- Works with any JDBC connection
- Volunteer developers, incl. Jeff Jensen
- Moved to GitHub (dbunit-extension), 2025
- Latest: 3.5.3, 18 Nov 2026
- First release: 1.0, Feb 2002
Overview
DbUnit is a free, open-source Java library for tests that use a database. It puts tables into a known state before each test by loading a dataset (from Flat XML, XML, CSV, JSON, YAML or Excel files, or built in code), and after the test it compares the tables with an expected dataset. First released in February 2002, it is licensed under LGPL 2.1 and published on Maven Central.
After a long quiet period (the old dbunit.org site still shows 2.4.9 from 2012), the project moved to GitHub as dbunit-extension and is very active again: 3.0.0 (January 2025) dropped JUnit 4 and added JUnit 5 support, 3.5.0 (August 2026) added a DbUnitExtension for JUnit 5 and 6, a JSON dataset format, MariaDB and H2 2.x support and PostgreSQL json/jsonb and array types, and 3.5.3 followed on 18 November 2026.
DbUnit fits Java teams that want data-driven database tests with readable dataset files, especially teams with existing DbUnit datasets. Buyers should note that it is Java only, that it manages data rather than starting databases (pair it with a real or containerised database), that JUnit 4 users must stay on 2.x or migrate, that the annotation-driven setup and Spring TestContext integration were still in a 3.6.0 snapshot in November 2026, and that the GitHub project is small (21 stars) compared with its long history.
Key Featuresโ
Datasetsโ
Test data comes from Flat XML, XML, CSV, JSON, YAML or Excel files, from datasets built in code with DataSetBuilder, or from a live query. Large datasets can be streamed.
Database Operationsโ
Before a test, datasets are applied with operations such as CLEAN_INSERT, INSERT, UPDATE, REFRESH, DELETE, DELETE_ALL and TRUNCATE_TABLE.
Table Assertionsโ
After a test, tables are compared with an expected dataset. ValueComparer implementations allow tolerances, greater-than and less-than checks, null checks, string containment and ignoring milliseconds in timestamps.
JUnit 5 and 6 Extensionโ
Since 3.5.0, DbUnitExtension manages DbUnit within the JUnit 5 and 6 lifecycle. Tests can also use IDatabaseTester or DBTestCase.
Row Count Checkโ
An opt-in check catches teardown mistakes such as leftover rows; the project suggests running it on a schedule, such as nightly.
Data Import and Exportโ
A Maven plugin and an Ant task import and export data outside tests, and an Eclipse plugin edits datasets in a grid.
Best Selling Pointsโ
- Known database state before every test, from readable files.
- Six dataset file formats, including JSON and YAML.
- Table-level assertions with flexible value comparers.
- Database-specific type support for PostgreSQL, Oracle, SQL Server and others.
- Free, mature (since 2002) and actively released again in 2025โ2026.
- Runs on Java 8 and later.
Supported Integrationsโ
Test Frameworks
- JUnit 5 and 6 (DbUnitExtension)
- IDatabaseTester
- DBTestCase
- Spring TestContext (3.6.0 snapshot)
Build and Tools
- Maven Central
- dbUnit Maven plugin
- Ant task
- Eclipse plugin
Dataset Formats
- Flat XML
- XML
- CSV
- JSON
- YAML
- Excel
Popular Customersโ
DbUnit is a community open-source project and doesn't publish a user list.
Supported Databasesโ
Databases with specific support in dbUnit 3.x.
- PostgreSQL
- Oracle
- MS SQL Server
- MySQL / MariaDB
- H2 / HSQLDB
- DB2
Database Detailsโ
- Type factories: H2, HSQLDB, MariaDB, Mckoi, MS SQL Server, Oracle and PostgreSQL have vendor-specific data type support.
- PostgreSQL: uuid, interval, inet, citext, large objects, enums, PostGIS geometry, json/jsonb and arrays.
- Oracle: LOBs, XMLType and SDO_GEOMETRY.
- Metadata handlers only: DB2, MySQL and Netezza.
- Other databases: DbUnit works over JDBC; the databases page doesn't list support beyond these.
How Tests Runโ
- Add the dependency:
org.dbunit:dbunitfrom Maven Central (3.5.3 as of November 2026). - Prepare: point DbUnit at a JDBC connection and a dataset file; it applies the dataset (usually CLEAN_INSERT) before each test.
- Verify: compare tables with an expected dataset after the code under test runs.
- Database: DbUnit doesn't start databases; use a developer or CI database, or a container. The project recommends one database instance per developer and small, focused datasets.
- Java: the jar targets Java 8 and the core API runs on JDK 8; JUnit 6 classes need Java 17.
Reportingโ
DbUnit has no reporting of its own. Failed table comparisons appear as assertion failures in your test runner's reports, with the differing values, and failure handling can be customised.
Security & Complianceโ
DbUnit runs in your own test process against the database you configure, so data stays in your environment. Its operations delete and insert data, so it must never point at a production database. The project publishes no certifications.
Pricingโ
DbUnit is free.
| Component | Price | Licence |
|---|---|---|
| dbUnit library | $0 | LGPL 2.1 |
| Maven plugin, Ant task, Eclipse plugin | $0 | Open source |
- Your only costs are the test database and CI compute.
Strengthsโ
- Simple, readable data setup and verification.
- Many dataset formats, including JSON and YAML.
- Detailed type support for PostgreSQL and Oracle.
- Mature, with over 20 years of use.
- Frequent releases since 2025 (nine 3.x releases).
- Runs on Java 8 and later.
Limitationsโ
- Java only.
- Manages data, not database instances.
- JUnit 4 support was dropped in 3.0.0.
- Annotation-driven setup and Spring integration were not released as of November 2026 (3.6.0 snapshot).
- The old dbunit.org site still shows 2012 information, which confuses new users.
- A small active community on GitHub.
Best Fit Scenariosโ
- Java teams that want known, file-based test data for database tests.
- Teams with existing DbUnit XML datasets moving to JUnit 5 or 6.
- Projects verifying table contents after service or DAO calls.
- Teams pairing DbUnit with real databases, including containerised ones.
- Oracle and PostgreSQL projects needing vendor-specific types in datasets.
- Teams exporting production-like data to files for tests with the Maven plugin.