Documentation

Documentation
V5 Documentation

NCrunch.Framework.IsolatedAttribute

NCrunch.Framework Attribute

Purpose

The Isolated attribute can be used to declare a test to only be run in an isolated task runner process. This attribute is defined in the NCrunch.Framework DLL.

Tests that are marked with this attribute will be executed in a process that is spawned specifically for the test alone. When the test completes execution, the process will be torn down and will not be reused for other tests.

It is also possible to apply this attribute to an entire fixture - in which case all tests within the fixture will be executed within the same process.

This attribute can also be applied at assembly level, in which case all fixtures within the assembly will be individually executed in isolation.

Declaration In NCrunch.Framework.dll

namespace NCrunch.Framework
{
    public class IsolatedAttribute: Attribute
    {
    }
}

You can declare this in your own code if you want NCrunch to use it - or otherwise reference the attribute from NCrunch.Framework.dll.

Usage example

[NCrunch.Framework.Isolated]
[Test]
public void MyTest()
{
	...

Recommendations

This attribute is very useful for tests that can only execute in a certain sequence, have a dependency on clean process state, or otherwise make a mess of their execution environment. Using this attribute on multi-threaded tests can also reduce the risk of race conditions and intermittent pass/fail scenarios.

Because there is significant overhead involved in spawning a new process for only one test, it is not recommended that you use this attribute widely within your code base.

Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download