Hi Brian,
I have experienced a similar kind of situation.
Storing data to DB and retaining them to previous state are not ideally unit tests. They are Integration test cases.
In order to perform the integration tests (insert / update operations ) without affecting the actual data ,I would suggest the following
1. Use different database(change the name of the actual DB) , and let the schema remain the same as the actual DB.
2. Point the unit tests to the newly created DB.
3. Now how do we create a new DB , for running the tests alone in an automated way ?
Ans : Have the SQL scripts listed in a batch file , such as this.(here i presume you are using SQL SERVER)
E.g., sqlcmd -i c:\data\runscripts\InventoryMonthEnd.sql
Specify the batch file , which lodges this sql statemet(s) to be executed in MSBuild process.
Sample MSBuild Task .
<ItemGroup>
<StoredProcScripts Include="$(RelativeSPDir)/*.sql" />
</ItemGroup>
<Target>
<Exec Command="isql -E -n -b -d DBName -i %(StoredProcScripts.Identity)" Condition="'%(StoredProcScripts.Identity)' != ''"/>
</Target>
Hope this helps.
Thanks ,
Vijay.