Hi All,
MSTest has a [ClassCleanup()] attribute, which needs to be static as far as I can tell. I like to run through after my unit tests have run,and clean up my database. This all works great, however when I go to our build server and use our Nant build script, it seems like the unit tests are run with NUnit. NUnit doesn't seem to like the cleanup method to be static. It therefore ignores my tests in that class. What can I do to remedy this? I prefer to not use [TestCleanUp()] as that is run after each test. Does anyone have any suggestions? I know [TestCleanup()] aids in decoupling, but I really prefer the [ClassCleanup()] in this situation. Here is some example code.
////Use ClassCleanup to run code after all tests have run
[ClassCleanup()]
public static void MyFacadeTestCleanup()
{
UpdateCleanup();
}
private static void UpdateCleanup()
{
DbCommand dbCommand;
Database db;
try
{
db = DatabaseFactory.CreateDatabase(TestConstants.DB_NAME);
int rowsAffected;
dbCommand = db.GetSqlStringCommand("DELETE FROM tblA WHERE biID=@biID");
db.AddInParameter(dbCommand, "biID", DbType.Int64, biToDelete);
rowsAffected = db.ExecuteNonQuery(dbCommand);
Debug.WriteLineIf(rowsAffected == TestConstants.ONE_ROW, string.Format("biId '{0}' was successfully deleted.", biToDelete));
} catch (SqlException ex) {
} finally {
dbCommand = null;
db = null;
biDelete = 0;
}
}
Thanks for any pointers and yes i realize I'm not catching anything. I need to get passed this hurdle first.
Cheers, ~ck in San Diego