- 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.DuplicateByDimensionsAttribute
NCrunch.Framework Attribute Introduced NCrunch v4.4Purpose
The DuplicateByDimensionsAttribute can be applied to tests, fixtures, or assemblies to enable multiple copies of these tests to be created and parameterised within the NCrunch runner. NCrunch will create a new copy of each test according to each parameter supplied to the attribute. When a copy of the test is executed, it is able to determine the value of its parameter using the NCrunchEnvironment.GetDuplicatedDimension method.
The test clones are effectively treated as separate tests by the entirety of the NCrunch engine. Throughout the UI, they are distinctively marked with a suffix describing their parameter value ('dimension').
This facility could be compared with similar test framework features such as NUnit's TestCase or XUnit Theories. However, there are some notable differences:
- DuplicateByDimensionsAttribute can be applied at all levels of a test suite, including at assembly level. This makes it possible to duplicate entire test suites according to parameters.
- DuplicateByDimensionsAttribute is applied at the runner level and requires no interaction with the test framework. This means it works seamlessly with all test frameworks supported by NCrunch, including those that do not have their own parameterisation features.
- DuplicateByDimensionsAttribute requires NCrunch to run. This means that tests relying on this attribute and values returned from NCrunchEnvironment.GetDuplicatedDimension will not function outside NCrunch. This is an important consideration for development projects where not all developers are using NCrunch to run their tests.
Declaration In NCrunch.Framework.dll
namespace NCrunch.Framework { public class DuplicateByDimensionsAttribute: Attribute { private string[] _dimensions; public DuplicateByDimensionsAttribute(params string[] dimensions) { _dimensions = dimensions; } public string[] Dimensions { get { return _dimensions; } } } }
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
The following example will create 3 tests with the same name, each with a different dimension shown in the Tests Window. Inside the code of these tests, each will call a different method as determined by the call to the NCrunchEnvironment.GetDuplicatedDimension method.
public class MyTestFixture { [Test] [NCrunch.Framework.DuplicateByDimensions("ABC", "XYZ", "123")] public void MyTest() { var dimension = NCrunch.Framework.NCrunchEnvironment.GetDuplicatedDimension(); if (dimension == "ABC") firstTestCase(); else if (dimension == "XYZ") secondTestCase(); else if (dimension == "123") thirdTestCase(); } private void firstTestCase() { } private void secondTestCase() { } private void thirdTestCase() { } }
Recommendations
This attribute can be used for executing a test suite across multiple platforms, where the platform is chosen at runtime during the test.
It can also provide a simple way to perform parameteried testing outside the constaints of the test framework(s) in use.