At a glance
| Supported databases | Any JDBC database; specific guides for ten engines |
| Data generation | No generators: loads fixture datasets you write or export |
| Masking | Not documented |
| Referential integrity | Dataset order and operations are your responsibility |
| CI/CD integration | Runs inside JUnit, Maven or Ant builds |
| Test automation | Setup and expected-state assertions for JUnit 5/6 tests |
| Data volume or subsetting | Small fixture datasets; export from live data is possible |
| Deployment | Java library (Java 8+ core API) |
| Licensing | Free, GNU LGPL 2.1 |
DbUnit suits Java teams that write JUnit integration tests against a real database and want each test to start from a defined data set and assert on table contents afterwards. It is free and works with any JDBC database. It does not start databases for you, so it is often paired with Testcontainers, and the 3.x line requires JUnit 5 or 6 rather than JUnit 4.
Overview
DbUnit is a long-running open source Java project that extends JUnit for database-driven tests. Before a test, it applies a dataset to the database with an operation such as CLEAN_INSERT (delete then insert), REFRESH or TRUNCATE_TABLE; after the test, it can read the actual tables and compare them with an expected dataset. It can also export data from a live database into dataset files, which is a common way to create the first fixtures.
Development moved to GitHub (repository dbunit/dbunit-extension, documentation at dbunit.github.io). Version 3.0.0 (25 January 2025) added JUnit 5 support and dropped JUnit 4; 3.5.0 (August 2026) added a DbUnitExtension for JUnit 5 and 6, a JSON dataset format and MariaDB and H2 2.x support. The core API still targets Java 8 bytecode, while building the project requires JDK 17.
Key features
- Dataset formats: flat XML, XML, CSV, JSON, YAML and Excel, plus datasets built in code or from a live query
- Database operations INSERT, UPDATE, DELETE, DELETE_ALL, TRUNCATE_TABLE, REFRESH and CLEAN_INSERT
- Assertions that compare actual table or query contents with expected datasets
- DbUnitExtension for JUnit 5 and 6 (Jupiter) lifecycle management, added in 3.5.0
- Export of existing database data into dataset files for fixtures
- Database-specific guides for ten engines, including PostgreSQL, MySQL, MariaDB, SQL Server, Oracle, Db2, H2 and HSQLDB
- Ant task and a companion dbunit-maven-plugin
Integrations and ecosystem
Pros and cons
Pros
- Free and open source with frequent 2026 releases
- Works with any JDBC database
- Many dataset formats, including JSON, YAML, CSV and Excel
- Expected-dataset assertions check the whole table state, not only return values
Cons
- Java only
- JUnit 4 support was dropped in 3.0.0, so JUnit 4 suites must stay on 2.x or migrate
- Does not create or start databases; you supply the database (for example with Testcontainers)
- The old dbunit.org site is stale, which can mislead when checking versions
Pricing
DbUnit is free, open source software under the GNU Lesser General Public License 2.1, published to Maven Central as org.dbunit:dbunit. There is no paid edition.
Pricing checked on the vendor's official page on 7 November 2026. Prices change; confirm before buying.
Who it is best for
Java teams writing JUnit 5 or 6 integration tests that need a known database state before each test and table-level assertions afterwards.
Typical use cases
- Resetting tables to a fixture before each repository or DAO test
- Verifying that a service call left the expected rows in several tables
- Exporting a small slice of a shared test database into versioned fixture files
- Running the same data-driven tests against H2 locally and PostgreSQL in CI
Who should look elsewhere
- Teams testing stored procedures inside SQL Server or PostgreSQL in SQL itself: see tSQLt or pgTAP.
- Teams that need large volumes of realistic synthetic data rather than hand-written fixtures.
Verdict
DbUnit is a mature, free option for putting JDBC databases into a known state and asserting on their contents in Java tests, and its 2025 and 2026 releases have modernised it for JUnit 5 and 6. It covers fixtures and assertions only, so plan to combine it with a way to provision the database, such as Testcontainers.
Frequently asked questions
Is DbUnit still maintained?
Yes. Releases 3.3.0 to 3.5.2 shipped between July and September 2026, with development on GitHub. The dbunit.org site still shows 2.4.9 from 2012 and is out of date.
Does DbUnit support JUnit 5?
Yes. Version 3.0.0 added JUnit 5 support and dropped JUnit 4, and 3.5.0 added a DbUnitExtension for JUnit 5 and 6.
Is DbUnit free for commercial use?
DbUnit is licensed under the GNU LGPL 2.1, which allows use as a library in commercial projects; read the licence for the conditions on modifying and redistributing DbUnit itself.
Which Java version does DbUnit need?
The 3.5.0 notes say JDK 8 is enough for the core API and the jar targets Java 8 bytecode, while building and running DbUnit's own tests requires JDK 17 or newer.
Sources
- DbUnit documentation site
- DbUnit changes report
- DbUnit GitHub repository (LGPL 2.1)
- dbUnit 3.3.0 release announcement
Checked November 2026.
Listed in: Database Testing & Test Data.
How we research reviews and what star ratings mean: our editorial method.