Datasets
Overview
The IDataSet interface represents a collection of tables — the primary abstraction dbUnit uses to manipulate tabular data, whether it comes from a file, a live database, or is built programmatically. Its core contract:
getTableNames()/getTables()/getTable(String)— the tables in the dataset.iterator()/reverseIterator()— insertion-order (and reverse) access, used by e.g.DatabaseOperation.INSERT/DELETE_ALLto respect foreign-key ordering.isCaseSensitiveTableNames()— whether table name lookups are case-sensitive.
ITable represents one table:
its ITableMetaData (columns), row count, and getValue(row, column) cell
access. See ITable & Table Metadata for the full
class reference.
Building Datasets Programmatically
DefaultDataSet is the
basic mutable IDataSet implementation used to construct datasets in code
rather than loading them from a file.
DataSetBuilder is a
fluent builder on top of it for the common case, avoiding hand-built
DefaultTable/Column wiring. Column data types default to UNKNOWN and
are resolved at runtime by dbUnit.
Single-table example:
IDataSet dataSet = new DataSetBuilder()
.table("FOO")
.columns("ID", "NAME")
.row(1, "Alice")
.row(2, "Bob")
.build();Multi-table example:
IDataSet dataSet = new DataSetBuilder()
.table("FOO")
.columns("ID", "NAME")
.row(1, "Alice")
.table("BAR")
.columns("X")
.row(42)
.build();Dataset Formats and Decorators
Each of the following is a focused page — file-based formats first, then the
programmatic/live sources, then the decorators that wrap any IDataSet/
ITable to add behavior, and finally the cross-cutting rules for how a
field’s text becomes a typed value:
| Page | Covers |
|---|---|
| Flat XML | FlatXmlDataSet — one XML element per row, the most commonly used file format. |
| XML | XmlDataSet — the original, more verbose XML format. |
| CSV | CsvDataSet — one CSV file per table, plus a table-ordering.txt manifest. |
| JSON | JsonDataSet — one top-level key per table, values as row-object arrays. |
| YAML | YamlDataSet — one top-level key per table. |
| Excel (XLS) | XlsDataSet — one sheet per table. |
| SQL*Loader | SqlLoaderControlDataSet — builds a dataset from Oracle SQL*Loader control files. |
| Query-Based | QueryDataSet — tables populated from arbitrary SQL queries against a live connection. |
| Streaming Datasets | StreamingDataSet — forward-only, low-memory access over a producer. |
| Data File Loader | DataFileLoader implementations — load a dataset file from the classpath, with ReplacementDataSet substitution built in. |
| Decorators | CompositeDataSet, FilteredDataSet, SortedTable/SortedDataSet, ReplacementDataSet, TableDecoratorDataSet, CachedDataSet. |
| Dataset Values | Not a format — how a field’s text becomes a typed column value in any of the above: nulls, empty strings, [TEXT|BASE64|FILE|URL] and [now…] syntax, UUID literals, booleans/numbers from strings, and Flat XML column sensing. |
For a live database as a dataset source (IDatabaseConnection.createDataSet()),
see Connections & Configuration.


