The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Database test framework.

SYNOPSIS

    use DBUnit ':all';

DESCRIPTION

Database test framework to verify that your database data match expected set of values. It has ability to populate dataset and expected set from xml files.

EXPORT

None by default.

reset_schema populate_schema expected_dataset xml_expected_dataset dataset xml_dataset by tag 'all'

ATTRIBUTES

connection_name
load_strategy

INSERT_LOAD_STRATEGY(default) Deletes all data from tables that are present in test dataset in reverse order unless empty table without attribute is stated, that force deletion in occurrence order In this strategy expected dataset is also tested against number of rows for all used tables.

REFRESH_LOAD_STRATEGY Merges (update/insert) data to the given dataset snapshot. In this scenario only rows in expected dataset are tested.

primary_key_values_stash

This option is stored as hash_ref: the key is the table name with the schema prefix and value is stored as array ref of primary key's values.

primary_key_definition_cache

This option is stored as hash_ref: the key is the table name with the schema prefix and value is stored as array ref of primary key column names.

METHODS

reset_schema

Resets schema

drop_objects

Removes existing schema

create_tables
objects_to_create

Returns list of pairs values('object_type object_name', create_sql, ..., 'object_typeN object_nameN', create_sqlN)

TODO - extend detection for complex plsql blocks

populate_schema

Populates schema

rows_to_insert
dataset

Synchronizes/populates database to the passed in dataset.

dataset( table1 => [], #this deletes all data from table1 (DELETE FROM table1) table2 => [], #this deletes all data from table2 (DELETE FROM table2) table1 => [col1 => 'va1', col2 => 'val2'], #this insert or update depend on strategy table1 => [col1 => 'xval1', col2 => 'xval2'], )

insert

Inserts data

merge

Merges passed in data

update

Updates table values.

has_primary_key_values

Returns true if passed in dataset have primary key values

primary_key_values
delete_data

Deletes data from passed in tables.

tables_to_delete
tables_to_delete_explicitly

Returns list of table that are part of dataset table and are represented by table without attributes

  table1 => [],

  or in xml file

  <table1 />
expected_dataset

Validates database schema against passed in dataset.

expected_dataset_for_insert_load_strategy

Validates expected dataset for the insert load strategy.

validate_number_of_rows

Validates number of rows.

validate_datasets

Validates passed exp dataset against fetched rows. Return undef if there are not difference otherwise returns validation error.

expected_dataset_for_refresh_load_strategy

Validates expected dataset for the refresh load strategy.

validate_expexted_dataset

Validates passed exp dataset against database schema Return undef if there are not difference otherwise returns validation error.

compare_datasets

Compares two dataset hashes using passed in keys Returns undef if there are not difference, otherwise difference details.

format_values
retrive_tables_data

Returns retrieved data for passed in tables

retrive_table_data

Returns retrieved data for passed in table.

primary_key_hash_value

Returns primary key values hash.

reset_sequence

Resets passed in sequence

xml_dataset

Loads xml file to dataset and populate/synchronize it to the database schema.

<dataset load_strategy="INSERT_LOAD_STRATEGY" reset_sequences="emp_seq"> <emp ename="scott" deptno="10" job="project manager" /> <emp ename="john" deptno="10" job="engineer" /> <emp ename="mark" deptno="10" job="sales assistant" /> <bonus ename="scott" job="project manager" sal="20" /> </dataset>

xml_expected_dataset dataset

Loads xml file to expected dataset and validated it against the database schema.

apply_properties
xml_dataset_handler
load_xml

Loads xml

_load_file_content

COPYRIGHT

The DBUnit module is free software. You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file.

SEE ALSO

DBIx::Connection

AUTHOR

Adrian Witas, <adrian@webapp.strefa.pl</gt>

See also