General Feedback

Difference between ExclusivelyUses and Isolated.

Started by GreenMoose on 7,249 views

Hi.

I have test structures something like below:

public abstract TestBase() {}
public abstract IntegrationTest : TestBase {}
[TestFixture]
public MyClassTest : IntegrationTest


I want my integration tests (hitting datbase) to not be run in parallel, but since it takes about ~10sec to wire up the test session (using NHibernate), I want as much as possbile tests for an integration test to be run within same process (to keep it fast since first test always takes ~10sec to initialize the static session factory).

So,
1) do [ExlusiveUses("Database")] and [Isolated] work in similar way for this, or am I better of with one or the other?
2) Does it matter that the abstract base class does not have [TestFixture] attribute?

Thanks.
Hi,

It's correct to use the 'ExclusivelyUsesAttribute' for this task. I recommend against using 'IsolatedAttribute', as this will cause each test run to be in a new process (which is counter to the goals you describe above).

Provided the integration tests all have the same exclusively used resource, they should run safely in sequence and will most likely use the same task runner process, although this isn't a rule, and there isn't a way to force to keep them in the same process.

The TestFixture attribute standing alone no longer makes any difference from NUnit 2.5 onwards, so there's no need to specify it. If you have a test class that contains tests but you do not want the test runner to execute them, marking the class as abstract will prevent the running from doing so. You'll notice that tests declared in an abstract class will still exist as part of any non abstract fixture that inherits from it, so this is a great way to re-use tests for difference scenarios.

Cheers,

Remco

Post a reply

Log in to reply.