如何连续运行NUnit测试夹具?

[英]How to run NUnit test fixtures serially?


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 scripts. This all used to work just fine prior to Resharper 5.1.

我在C#/ NUNit中实现了几套集成测试。每个测试套件都是一个单独的类,每个夹具设置从脚本创建并填充SQL Server数据库。这一切都曾经在Resharper 5.1之前工作得很好。

Unfortunately, Resharper 5.1 begins to run several fixtures at the same time. This is a breaking change - they are all attempting to create and populate the same database, which obviously ends up in an mess. Is there any way I could have Resharper run my test fixtures serially?

不幸的是,Resharper 5.1开始同时运行多个灯具。这是一个重大改变 - 他们都在尝试创建和填充相同的数据库,这显然最终会陷入混乱。有什么方法可以让Resharper连续运行我的测试夹具吗?

If not, what would you suggest to run my NUnit test fixtures serially, one fixture at a time? The order in which individual tests run does not matter.

如果没有,你会建议连续运行我的NUnit测试夹具,一次一个夹具?单个测试运行的顺序无关紧要。

4 个解决方案

#1


22  

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...

我不知道是否有可能阻止ReSharper并行运行测试;如果没有,以下hack可能会起作用:使用静态只读Monitor成员创建一个静态类。然后,在[TestFixtureSetUp]中,在监视器上调用Enter(),并在[TestFixtureTearDown]中调用监视器上的Exit()。这样,一次只允许运行一个测试夹具。不漂亮,但......

#2


1  

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.

你确定吗 ?我只是尝试了这个...通过在3个差异NUnit灯具中测试下面的形式的跟踪,然后是“全部运行”。似乎没有并行运行。

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)

我看到的输出是:(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

#3


0  

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

#4


0  

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.

给它们字母名称,即在它们前面加上表示其运行顺序的字母。如果你需要这个,你应该能够接受这个令人讨厌的命名约定。

智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2011/06/21/7206377516be0aabdf1b9c42f5373b04.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告