问题描述:

I was running tests in VS2013 with Resharper 8, which integrated with an external process and redirected its output. I'm not seeking guidance on what qualifies as a unit test, because I find the test runner to be a nicer driver for any test than a console app.

This process was a database and so my SetUp and TearDown methods unsurprisingly did the opposites of each other and would absolutely step on each other if allowed to run concurrently.

They did not get to step on each other, because whenever two tests were started by the running simultaneously, they would lock up.

Latest Version 7 of Resharper did not have this issue.

Tinkering with the unit test settings in Resharper > Options > Unit Testing did not help.

网友答案:

How to run NUnit test fixtures serially? -- is close to working.

On my test fixture base (and I always run base.SetUp() at the beginning of derived SetUp), I added the following:

    [SetUp]
    protected virtual void SetUp()
    {
        FixtureHandle.Wait();
    }

    [TearDown]
    protected virtual void TearDown()
    {
        FixtureHandle.Set();
    }

FixtureHandle is a ManualResetEvent. This prevents NUnit from being too damn good and fast.

网友答案:

The above answer, from @nik.shornikov, will work, but in Resharper 2016.2 and later (and probably also in earlier versions) you can do this via an option, without writing any code. Please see my answer to Is there a way to *prevent* ReSharper from running an assembly's unit tests in parallel? for full details.

相关阅读:
Top