Multiple TestInitialize attributes in MSTEST
Using MSTEST in VS2012.3 .NET4.5 and R# for the test runner.
The code below works in the order 1,2,3,4.
However I'm concerned that it may not always execute in this order as
multiple TestInitialize attributes are not supported MSDN
Question: Is this allowed, and do the docs just mean that multiple
TestInitialize attributes are not allowed in the same class?
I would like to keep this structure as have many integration tests
inheriting off TransactedTestBase, yet requiring different SQL scripts to
setup.
[TestClass]
public class DelegationTest : TransactedTestBase
{
[TestInitialize]
public void Setup()
{
Console.WriteLine("2 Setup");
//var script = "INSERT INTO blah...";
//var sqlConnect = new SqlConnection(dbConnection.ConnectionString);
//sqlConnect.Open();
//var server = new Server(sqlConnect);
//var database = server.Databases[sqlConnect.Database];
//database.ExecuteNonQuery(script);
}
[TestMethod]
public void TestMethod1()
{
Console.WriteLine("3 Test Method");
}
}
[TestClass]
public class TransactedTestBase
{
//protected userEntities userEntities;
//private TransactionScope scope;
//public static SqlDatabase dbConnection;
//private const bool ShouldWriteToDB = true;
//private const bool ShouldWriteToDB = false;
[TestInitialize()]
public virtual void TestStart()
{
Console.WriteLine("1 TestStart");
//if (ShouldWriteToDB)
//{
// dbConnection =
EnterpriseLibraryContainer.Current.GetInstance<SqlDatabase>("DBConnect");
// return;
//}
//scope = new TransactionScope(TransactionScopeOption.RequiresNew);
//user = new userEntities();
//dbConnection =
EnterpriseLibraryContainer.Current.GetInstance<SqlDatabase>("DBConnect");
}
[TestCleanup()]
public virtual void TestEnd()
{
Console.WriteLine("4 TestEnd");
//if (ShouldWriteToDB) return;
//scope.Dispose();
}
}
No comments:
Post a Comment