object aliasing between TestFixtures that inherit from the same abtract TestFixture

18 views
Skip to first unread message

Charles Ritchea

unread,
May 9, 2013, 4:14:03 PM5/9/13
to nunit-...@googlegroups.com
This problem is non-deterministic as it involves race conditions. I have many TestFixtures that use the same resource object assigned to a local variable. It was my understanding that TestFixtures don't share state unless they are nested. Occasionally it appears that aliasing is occurring between TestFixtures, so that if I change a value in one TestFixture it changes the value in the other TestFixture. I'm not running these in Parallel. I'm just running them with nunit-console.exe via NAnt, or ReSharper (I know I know). The only thing I can think of is that they are both inherited from the same base abstract TestFixture. I've gotten into the habit of giving the objects new Guid's as thats the only thing they need to be unique in case everything else is aliased, yet it appears when I give them new Guids that multiple TestFixtures are running in Parallel and they end up using which ever Guid gets there first.  My question is if its even possible for TestFixtures to share state like this? I thought each TestFixture was run like a separate process? I know work arounds, but this is like "spooky behaviour at a distance" that I thought I'd bring up.

Charlie Poole

unread,
Jul 14, 2013, 12:40:11 PM7/14/13
to NUnit-Discuss
Since nobody has replied to this old post, I'll give it a shot.

If your abstract TestFixture has static members that can be set by the fixtures that derive from it, then it's possible for such changes to effect multiple fixtures. This should not be possible with instance members, since each fixture gets a separate instance. Naturally, it's quite possible for individual test methods within a fixture to interfere with one another by setting instance or static members.

TestFixtures do not run in a separate process... they run along with all your other test fixtures.

Charlie


On Thu, May 9, 2013 at 1:14 PM, Charles Ritchea <novat...@gmail.com> wrote:
This problem is non-deterministic as it involves race conditions. I have many TestFixtures that use the same resource object assigned to a local variable. It was my understanding that TestFixtures don't share state unless they are nested. Occasionally it appears that aliasing is occurring between TestFixtures, so that if I change a value in one TestFixture it changes the value in the other TestFixture. I'm not running these in Parallel. I'm just running them with nunit-console.exe via NAnt, or ReSharper (I know I know). The only thing I can think of is that they are both inherited from the same base abstract TestFixture. I've gotten into the habit of giving the objects new Guid's as thats the only thing they need to be unique in case everything else is aliased, yet it appears when I give them new Guids that multiple TestFixtures are running in Parallel and they end up using which ever Guid gets there first.  My question is if its even possible for TestFixtures to share state like this? I thought each TestFixture was run like a separate process? I know work arounds, but this is like "spooky behaviour at a distance" that I thought I'd bring up.

--
You received this message because you are subscribed to the Google Groups "NUnit-Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nunit-discus...@googlegroups.com.
To post to this group, send email to nunit-...@googlegroups.com.
Visit this group at http://groups.google.com/group/nunit-discuss?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Charles Ritchea

unread,
Jul 14, 2013, 5:46:58 PM7/14/13
to nunit-...@googlegroups.com
Thanks for the thorough explanation Charlie. Fortunately this problem only arose in legacy code that was using a singleton to statically deserialize xml to be used in POST data to a RESTful API and I've had a chance to rewrite everything to deserialize on demand which means independent objects now. Previously, anytime I wanted to tweak the data there was a risk of the changes effecting other tests, but not anymore. I'm VERY new at this. In retrospect the aliasing seems like an obvious risk.


--
You received this message because you are subscribed to a topic in the Google Groups "NUnit-Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nunit-discuss/o2jaCxx_UJ4/unsubscribe.

To unsubscribe from this group and all its topics, send an email to nunit-discus...@googlegroups.com.

To post to this group, send email to nunit-...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages