Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I prevent my NUnit tests from running in parallel sometimes

I'm using the NUnit test runner included in Monodevelop. I have 2 tests which must interact with static resources so I need them to run serially rather than parallel. I've tried using something like

static string Locker="foo";
[Test]
public void Test1()
{
  lock(Locker)
  {
    //....
  }
}
[Test]
public void Test2()
{
  lock(Locker)
  {
    //....
  }
}

This doesn't seem to work though. Is there some other way?

like image 709
Earlz Avatar asked Jan 18 '26 17:01

Earlz


2 Answers

I'm using this approach when REALLY needed (i think it's a bad idea):

using System.Threading;
private ManualResetEvent FixtureHandle = new ManualResetEvent(true);
[SetUp]
public void SetUp()
{
    FixtureHandle.WaitOne();
}
[TearDown]
public void TearDown()
{
    FixtureHandle.Set();
}
[Test]
public void Test1()
{
  //only test
}
[Test]
public void Test2()
{
  //only test
}
like image 199
Giulio Caccin Avatar answered Jan 20 '26 06:01

Giulio Caccin


Dont know about Monodevelop but nunit console has command line argument /nothread

It should be something similar in Monodevelop i think

like image 30
Sanja Melnichuk Avatar answered Jan 20 '26 05:01

Sanja Melnichuk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!