Reputation: 16695
I'm trying to set-up a test initialise function that handles some basic database set-up tasks; here's my base class:
[ TestClass]
public class BaseTest
{
private SqlConnection sqlConnection;
protected SqlTransaction sqlTransaction;
[TestInitialize ()]
protected void InitialiseConnection()
{
// Set-up sqlTransaction
}
[ TestCleanup ()]
protected void RollbackConnection()
{
// Cleanup
}
Then I'm using it like this:
[ TestClass]
public class MyTest : BaseTest
{
[ TestMethod ]
public void MyFirstTest()
{
/// Access DB here crashes because sqltransaction is null
A breakpoint on the base class reveals that it isn't calling the InitialiseConnection
method. Have I missed something?
Upvotes: 2
Views: 357
Reputation: 7202
Make the method marked with TestInitialize
public instead of protected. I remember having similar problems when the signature didn't exactly match the one in the MSDN sample.
Upvotes: 5