Hi David -
Tests marked with InclusivelyUsesAttribute can still be run together if they are using the same resource.
Tests marked with ExclusivelyUsesAttribute cannot be run together if they use the same resource.
InclusivelyUsesAttribute is completely useless unless you use it in combination with ExclusivelyUsesAttribute, as 'inclusively' using a resource means that you have no problem with others making use of a resource, provided they aren't using it exclusively. Scenarios where InclusivelyUsesAttribute is needed are quite rare and probably would only appear in fairly complex cases - usually around database or file I/O.
See the following example:
Code:
using System.IO;
using NCrunch.Framework;
using NUnit.Framework;
public class MyLoggingFixture
{
[Test]
[InclusivelyUses("LoggingDirectory")]
public void FirstTestThatWritesToALogFile()
{
Directory.CreateDirectory("LoggingDirectory");
using (var file = new StreamWriter(@"LoggingDirectory\MyLogFile.log"))
{
file.WriteLine("Some stuff written to a log file in the log directory");
}
}
[Test]
[InclusivelyUses("LoggingDirectory")]
public void SecondTestThatWritesToALogFile()
{
Directory.CreateDirectory("LoggingDirectory");
using (var file = new StreamWriter(@"LoggingDirectory\AnotherLogFile.log"))
{
file.WriteLine("Some stuff written to a different log file in the logging directory");
}
}
[Test]
[ExclusivelyUses("LoggingDirectory")]
public void TestThatCleansUpTheLoggingDirectory()
{
if (Directory.Exists("LoggingDirectory"))
Directory.Delete("LoggingDirectory", true);
}
}
In the above example, there are two tests that write to different files within a logging directory. These tests can safely be run together (concurrently) in different processes, as they touch different files and don't step on each other's resources. However, the third test cannot safely be run concurrently with either of the other tests, as this test makes changes to the file system by deleting a directory required by the other tests to run.
So it can be said that the two tests writing to log files are making 'Inclusive' use of the logging directory, where the third test uses it 'exclusively'. When marked as such, NCrunch will avoid running the third test if either of the other tests is currently executing.
I hope this makes sense!
Cheers,
Remco