I have several suites of integration tests implemented in C#/NUNit. Each test suite is a separate class, each fixture setup creates and populates a SQL Server database from
I don't know whether it is possible to prevent ReSharper from running tests in parallel; if not, the following hack might work: Create a static class with a static readonly Monitor
member. Then, in [TestFixtureSetUp]
, call Enter()
on the monitor, and call Exit()
on the monitor in [TestFixtureTearDown]
. That way, only one test fixture will be allowed to run at a time. Not pretty, though...
Give them alphabetical names, i.e. prefix them with a letter that signifies their running order. If you need this to happen you should be able to accept this nasty naming convention too.
Unless the code being tested does its own transaction management, you can run each test inside a transaction. In that way, the different tests won't disturb each other. Also, you don't have to worry about cleaning up after each test, since the each test's transaction can simply abort after the test is completed.
In our projects, we usually let our integration tests derive from a class that looks more or less like this:
public class TransactionalTestFixture
{
private TransactionScope TxScope;
[SetUp]
public void TransactionalTestFixtureSetUp()
{
TxScope = new TransactionScope(TransactionScopeOption.RequiresNew,
new TransactionOptions {IsolationLevel = IsolationLevel.Serializable});
}
[TearDown]
public void TransactionalTestFixtureTearDown()
{
TxScope.Dispose();
}
}
Are you sure about this ? I just tried this out.. by putting a trace of the following form in tests in 3 diff NUnit fixtures followed by a "Run all". Doesn't seem to be running in parallel.
Trace.WriteLine(DateTime.Now.ToString("hh:mm:ss.ffff") + "VC:Start");
Trace.WriteLine(DateTime.Now.ToString("hh:mm:ss.ffff") + "VC:Done");
Output I see is : (R# Build 5.1.1753.1)
01:06:41.6639IOC
01:06:41.6649Done - IOC
01:06:41.6679VC:Start
01:06:41.6729VC:Done
01:06:41.2439Mef
01:06:41.6589Mef-Done