YAML

YamlDataSet reads and writes YAML dataset documents. Each toplevel key corresponds to a table, where the value is a list of rows. Each row is a sequence of key:value pairs, where the key corresponds to the table column.

YAML dataset document sample:

TEST_TABLE:
  - COL0: row 0 col 0
    COL1: row 0 col 1
    COL2: row 0 col 2
  - COL1: row 1 col 1
SECOND_TABLE:
  - COL0: row 0 col 0
    COL1: row 0 col 1
EMPTY_TABLE:

To specify null values, just omit the corresponding column key. In the above example, missing COL0 and COL2 keys of TEST_TABLE second row represents null values.

In contrast to Flat XML, table metadata is deduced from the sum of all rows for each table, not just the first — so a column that first appears on a later row is still picked up.

For what happens to a field value after parsing — empty strings, binary/BLOB syntax, literal and relative dates, UUID literals, and booleans/numbers from strings — see Dataset Values, which applies to every format.

Dependency

dbUnit depends on SnakeYAML to read/write YAML files, but marks it optional so projects that don’t use YamlDataSet don’t pull it in. Add it yourself to use this format:

<dependency>
  <groupId>org.yaml</groupId>
  <artifactId>snakeyaml</artifactId>
  <version>VERSION</version>
</dependency>

Without it on the classpath, reading or writing a YAML dataset fails with a DataSetException that names the dependency to add; using YamlProducer directly, as the Ant <operation format="yml"> step does, fails the same way with a DatabaseUnitRuntimeException. Datasets in other formats are unaffected.