How to run NUnit test fixtures serially?

前端 未结 4 1479
暗喜
暗喜 2020-12-29 05:04

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

4条回答
  •  清酒与你
    2020-12-29 05:30

    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();
        }
    }
    

提交回复
热议问题