Lately I've been looking at the unit tests being generated for NetTiers a quite common case for me is the following failure
Step_01_Insert : System.Data.SqlClient.SqlException : The INSERT statement conflicted with the FOREIGN KEY constraint ...
So I'm a bit curious how do you actually go about doing unit testing? Do you pre-fill the database with information based on the unit tests generated to allow them to pass successfully or do you tweak the generated code (alas it get overwritten each time you regenerate the NetTiers solution)?
I’m using VS2005 to do the unit testing instead of NUnit and VS2005 likes to set attributes on the methods being test cases to control such things as whether the test is enabled or not, timeout etc. What annoys me today is that all that tweaking of individual test cases is lost when the NetTiers solution is regenerated. What I’m been thinking about is to use partial classes to split the unit tests into
XXXTest.cs that is never overwritten and an XXXTest.generated.cs that is always overwritten.
The XXXTest.cs would be generated with attributed methods as today
From XXXTest.cs
[TestMethod]
public void Step_01_Insert()
{
// TODO: Establish necessary preconditions here
Step_01_Insert_generated();
// TODO: Provide additional verification here
}
From XXXTest.generated.cs
public void Step_01_Insert_generated()
{
Assert.IsTrue(DataRepository.AreaProvider.Insert(transactionManager, mock), "Insert failed");
System.Console.WriteLine("DataRepository.AreaProvider.Insert(mock):");
System.Console.WriteLine(mock);
}
Comments, suggestions? Anyone else interested?