- Overview
- Guides
- Concepts
- Considerations And Constraints
- Absolute File References
- Assembly Colocation Assumptions
- Concurrent Use Of Test Resources
- Cross Application Domain Testing
- Heavily Executed Code Under Test
- Implicit File Dependencies
- Multi Threaded Tests
- Netstandard Test Projects
- Project Atomicity
- Project Build Platform And Configuration
- Rdi Data Point Location
- Test Atomicity
- Unique Test Names
- Using NCrunch With Source Control
- Reference
- Global Configuration
- Overview
- Auto Adjust Clashing Marker Colours
- Build Log Verbosity
- Build Process Memory Limit
- Capabilities Of This Computer
- Coverage Marker Style
- Cpu Cores Assigned To NCrunch Or Ide
- Custom Environment Variables
- Disable Global Hotkey
- Engine Hosting Strategy
- Fast Lane Threads
- Fast Lane Threshold
- Grid Maximum Reconnection Attempts
- Grid Reconnection Delay
- Impact Detection Mode
- Listening Port
- Log To Output Window
- Logging Verbosity
- Marker Colours
- Max Failing Test Trace Log Size
- Max Number Of Processing Threads
- Max Passing Test Trace Log Size
- Max Test Runners To Pool
- NCrunch Tool Window Colors
- Node Id (Name)
- Password
- Performance Aggregation Type
- Performance Display Sensitivity
- Pipeline Optimisation Priority
- Rdi Storage Settings
- Sliding Build Delay
- Snapshot Storage Directory
- Solution Storage Data Limit
- Spinner Colours
- Terminate Test Runners On Complete
- Test Process Memory Limit
- Tests To Execute On This Machine
- Text Output Font
- Workspace Base Path
- Solution Configuration
- Overview
- Additional Files For Grid Processing
- Additional Files To Include
- Allow Parallel Test Execution
- Allow Tests In Parallel With Themselves
- Infer Project References Using Assembly
- Instrumentation Mode
- NCrunch Cache Storage Path
- Only Consider Tests Outofdate If Impacted
- Project Config File Storage Path
- Show Coverage For Tests
- Show Metrics For Tests
- Tests To Execute Automatically
- Project Configuration
- Overview
- Additional Files To Include
- Allow Dynamic Code Contract Checks
- Allow Static Code Contract Checks
- Analyse Line Execution Times
- Autodetect Nuget Build Dependencies
- Build Priority
- Build Process Cpu Architecture
- Build Sdk
- Collect Control Flow During Execution
- Consider Inconclusive Tests As Passing
- Copied Project Dependencies
- Copy Referenced Assemblies To Workspace
- Custom Build Properties
- Data Storage File Size
- Default Test Timeout
- Detect Stack Overflow
- Enable Rdi
- Files Excluded From Auto Build
- Framework Utilisation Types
- Ignore This Component Completely
- Implicit Project Dependencies
- Include Static References In Workspace
- Instrument Output Assembly
- Method Data Limit
- Ms Test Thread Apartment State
- Preload Assembly References
- Prevent Signing Of Assembly
- Proxy Process File Path
- Rdi Cache Size
- Required Capabilities
- Restrict Tostring Usage
- Run Pre Or Post Build Events
- String Length Limit
- Track File Dependencies
- Use Build Configuration
- Use Build Platform
- Use Cpu Architecture
- Runtime Framework
- Overview
- Atomic Attribute
- Category Attribute
- Collect Control Flow Attribute
- Distribute By Capabilities
- Duplicate By Dimensions
- Enable Rdi Attribute
- Environment Class
- Exclusively Uses Attribute
- Inclusively Uses Attribute
- Isolated Attribute
- Method Data Limit Attribute
- Requires Capability Attribute
- Restrict Tostring Attribute
- Serial Attribute
- String Length Limit Attribute
- Timeout Attribute
- Uses Threads Attribute
- Global Configuration
- Troubleshooting
- Tools
- Keyboard Shortcuts
- Manual Installation Instructions
NCrunch.Framework.ExclusivelyUsesAttribute
NCrunch.Framework AttributePurpose
The ExclusivelyUsesAttribute can be used to mark tests (or test fixtures) as making constrained use of a specific set of resources. The primary reason for this is to prevent concurrent execution of tests that do not support it.
This attribute can be found in the NCrunch.Framework assembly, which you can reference from your test project to make use of NCrunch's run-time features.
The attribute can be applied to both fixtures and tests, and also supports inheritance.
The attribute can also be applied at assembly level, in which case all tests within the assembly will be considered as making exclusive use of the specified resources.
When declaring the attribute, you specify a sequence of string values that are used to identify the resources your test is relying on during its execution. Any tests that make exclusive or inclusive (via InclusivelyUsesAttribute) use of one of the specified resources will be considered mutually exclusive with the decorated test and will not be run at the same time by NCrunch.
Note that the resource name declared with ExclusivelyUsesAttribute is effectively no more than an arbitrary mutex that prevents two similarly attributed tests from running concurrently - it does not need to correspond to a physical resource on the system. Resource naming is done purely for the sake of convention.
Declaration In NCrunch.Framework.dll
namespace NCrunch.Framework { public abstract class ResourceUsageAttribute: Attribute { private readonly string[] _resourceNames; public ResourceUsageAttribute(params string[] resourceName) { _resourceNames = resourceName; } public string[] ResourceNames { get { return _resourceNames; } } } public class ExclusivelyUsesAttribute: ResourceUsageAttribute { public ExclusivelyUsesAttribute(params string[] resourceName) : base(resourceName) {} } }
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.ExclusivelyUses("Database", @"c:\logfile")] [Test] public void MyTest() { ...
Recommendations
Tests most commonly need to make use of the InclusivelyUsesAttribute and ExclusivelyUsesAttribute when they are interacting with key files on the file system, with a database, or using a specific socket connection.
It is considered good practice to engineer your tests so that they do not need exclusive use of resources. Make use of random file names, random socket numbers and isolated database transactions where ever possible. Doing so will reduce the constraints on NCrunch's execution engine and reduce your test cycle times.
In the Tests Window, it is possible to view which tests are making inclusive/exclusive use of resources. Simply right click the column header and select the 'Exclusively Used Resources' column.
Where a physical resource doesn't exist, you can simply substitute its name for the name of an arbitrary mutex. The main function of this attribute is to declare some kind of name that can never be shared by two tests executing at the same time. So you could just use 'ExclusivelyUsesAttribute("LocksFiles")' on all the tests that can experience file locking issues. This would be better than marking each test with SerialAttribute, as the tests with ExclusivelyUsesAttribute would be unable to run concurrently with each other, where the SerialAttribute tests cannot run concurrently with anything (i.e. you may have other tests that can run perfectly normally without ever caring about the file locks).