This project is read-only.
Project Description
TDUnit is a unit testing utility similar to DBUnit.Net. TDUnit helps with unit testing database access by allowing you to keep identity columns and foreign key constraints enabled on your test database by allowing dependency values within the test data XML file.

TDUnit uses an XML file similar in spirit to DBUnit's to specify test data to be loaded into a database with one major difference. TDUnit allows for the creation of test data that contains identity columns and relationships between tables. For example in TDUnit you can load a customer row into the Customer table and then reference the auto generated ID (Identity Column) for the customer in the Order table. Although written in C# 3.0 it can be used from .Net 2.0 projects as long as the .Net Framework 3.5 is installed. By specifying the test data in XML files, the data required for the tests can be kept with the tests and TDUnit inserts and removes the test data. This allows your test database to remain empty, allowing for faster changes and easier distribution to the team.

TDUnit is used as a test utility, in that you do not need to inherit from certain classes to use it. Just instantiate the TestDataUtility class for the database you are using and call SetUp() on it. When done call TearDown(). You decide when the test data gets created and removed. The test data can be in an XML file and specified by file name, or you can add it as literal text right in the test you are writing. All of this makes TDUnit a very useful, powerful, and, hopefully, user friendly test utility. As of right now TDUnit works with MS SQL Server and SQLEXPRESS. However, the project was designed with extensibility in mind, so download the source code and create your own ScriptEngine and ScriptExecutionEngine classes by implementing IScriptEngine and IScriptExecutionEngine for your favorite DBMS. You can use SqlServerScriptExecutionEngine.cs and BasicSqlScriptEngine.cs as examples of what you need to do. SqlServerTestDataUtility makes instantiating a TestDataUtility object for MS SQL Server a breeze.

Here is an example of an XML test data file:

<TestData xmlns="http://tdunit.org/TestDataSchema.xsd">

<Table Name='Customer' PrimaryKey='ID' IsAutoIdentity='true' Alias="Cust">
<Row Name='CustomerRow' FirstName='Homer' LastName='Simpson' />
</Table>

<Table Name='Order' PrimaryKey='ID' IsAutoIdentity='true'>
<!-- CustomerID's value is being pulled from the Customer Table above using CustomerRow as the source of the ID. ID is an identity column set on the Customer table.-->
<Row Name='OrderRow1' CustomerID='$(Customer.CustomerRow.ID)' CreatedOn='2009-02-02'>
<Column Name='Name' Value="Homer Simpson's Order" />
</Row>
<!-- Here we are using the Alias for the Customer Table 'Cust' as the dependency value for CustomerID.-->
<Row Name='OrderRow2' CustomerID='$(Cust.CustomerRow.ID)' CreatedOn='2009-02-02'>
<Column Name='Name' Value="Homer Simpson's Other Order" />
</Row>
</Table>

<Table Name='Product' PrimaryKey='ID' IsAutoIdentity='true'>
<Row Name='ProductRow1' Description='Product Description' Price='10.95' />
<Row Name='ProductRow2' Description='Duff Beer' Price='1.95' />
</Table>

<Table Name='OrderLine' PrimaryKey='ID' IsAutoIdentity='true'>
<Row Name='OrderLineRow1' OrderID='$(Order.OrderRow1.ID)' ProductID='$(Product.ProductRow2.ID)' Quantity='12'/>
<Row Name='OrderLineRow2' OrderID='$(Order.OrderRow2.ID)' ProductID='$(Product.ProductRow1.ID)' Quantity='200'/>
</Table>

</TestData>

Any row in the test data file can be given a name and then referenced in following rows. Any columns from the named row can also be used in any rows that follow the named row. For instance, in the above example we could use $(Product.ProductRow1.Description) as a value for any column defined on a row that follows the Product table entry. The syntax for these dependency values is $(TableName/Alias.RowName.ColumnName).

Last edited Feb 11, 2009 at 12:22 AM by adargel, version 16