lundi 13 avril 2015

NUnit Rollback attribute seems to fail on SQL Server 2005

I'm using a nice little [Rollback] attribute on my NUnit database-level tests:



public class RollbackAttribute : Attribute, ITestAction
{
private TransactionScope _transaction;

public ActionTargets Targets {
get { return ActionTargets.Test; }
}

public void BeforeTest(TestDetails testDetails) {
_transaction = new TransactionScope();
}

public void AfterTest(TestDetails testDetails) {
_transaction.Dispose();
}
}


So I can then decorate my db-based tests like this:



[Test]
[Rollback]
public void TestGetAllActiveItems()
{
// Arrange
SetupTestData();

// Act
var results = GetAllActiveItems(string.Empty, string.Empty);

// Assert
Assert.IsNotNull(results);
}


The sample data I create and store in the SetupTestData() method is used for the test, and then discarded at the end of the test.


This works like a charm on SQL Server 2012 and 2014 on my local dev machine - but for some reason, it appears to fail miserably on our build & test machine, which is still using SQL Server 2005 (soon to be upgraded).


Any ideas why? I just see that my two items that I insert into the database in my SetupTestData() method are inserted once for each test method, and NOT rolled back at the end of each method, for some weird reason.... I don't see any errors or other indicators in the build / testrun logs - it just doesn't work and doesn't do the rollback on my build/test server.


Any pointers? Thoughts? Points to check?


Aucun commentaire:

Enregistrer un commentaire