MbUnit now supports the new attributes for Roy Osherove (ISerializable) to solve the database Rollback problem:
I will assume that you have read the article from Roy so I can skip explanation and show an example. Consider the following test fixture:
[TestFixture] [SqlRestoreInfo("connectionstring","databasename",@"c:\backups\nw.mbk")] public class NorthWindTest { [Test, RollBack] public void TestWithRollBack() {...} [Test, RestoreDatabaseFirst] public void TestWithRestoreFirst() {...} }
This example, which runs in MbUnit, is similar to what Roy has proposed: SqlRestoreInfo gives information that can be used to restore the db. TestWithRollBack is rolled back using Enterprise services, the database is restored before TestWithRestoreFirst is executed.
What about data abstraction ?
We would like to create a fixture and apply it to different Db provider (Oracle, MySql,etc..). Is this possible ? This is (will**) possible in a minimum of work, it is just a matter of changing SqlRestoreInfo to OracleRestoreInfo:
[TestFixture] public abstract class DbNorthwindTest { [Test, RollBack] public void TestWithRollBack() {...} [Test, RestoreDatabaseFirst] public void TestWithRestoreFirst() {...} } [SqlRestoreInfo("connectionstring","databasename",@"c:\backups\nw.mbk")] public class SqlNorthwindTest : DbNorthwindTest {} [OracleRestoreInfo("connectionstring","databasename",@"c:\backups\nwporacle.mbk")] public class OracleNorthwindTest : DbNorthwindTest {}
This example is quite neat and self-explenatory: SqlNorthwindTest will apply the fixture against a MsSql server using System.Data.SqlClient classes, while OracleNorthwindTest will test against Oracle.
**Currently, only SqlRestoreInfoAttribute is implemented.
Page rendered at Sunday, September 07, 2008 9:29:07 PM UTC
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.