Daily Usage Issues

NUnit 4 and ParallelizableAttribute

Started by GreenMoose on 1,058 views

[v5.13]

Background:
I'm working in a legacy xUnit project and I want to introduce the use of NUnit instead (for multiple reasons). Some people are using Macs and cannot be persuaded to take advantage of NCrunch.

Problem:
I noticed that when using [Parallelizable] with NUnit 4.3.2 (to make it "as fast" as xUnit for running tests), NCrunch warns about this usage and that it may cause instability.

Questions:
1) Does this mean that NCrunch can more reliably and automatically disable parallel test runs with xUnit, but not with NUnit?

2) Is there a recommended approach to avoid removing this attribute, while simply skipping it when NCrunch is the active runner? Or is a conditional mutex setup/teardown (used only if NCrunch is active) the best way to ignore the NCrunch warning, or would this approach still cause NCrunch to misbehave?

Thanks!
Hi, thanks for posting.


Questions:
1) Does this mean that NCrunch can more reliably and automatically disable parallel test runs with xUnit, but not with NUnit?


Yes. Xunit has a configuration option that, when passed in, can shut off all parallel behaviour. Our control over NUnit in this situation is somewhat more limited.


2) Is there a recommended approach to avoid removing this attribute, while simply skipping it when NCrunch is the active runner? Or is a conditional mutex setup/teardown (used only if NCrunch is active) the best way to ignore the NCrunch warning, or would this approach still cause NCrunch to misbehave?


A Mutex isn't sufficient, as NCrunch requires test execution to be entirely synchronous otherwise results tracking goes completely haywire.

The only way to solve this is to remove ParallelizableAttribute. If your team is using other tools, it might be best to do this with a compiler condition, i.e.:

#if !NCRUNCH
[Parallelizable]
#endif

Edited

Post a reply

Log in to reply.