Table of Contents

Class ModeDetector

Namespace
Splat
Assembly
Splat.dll

Provides static methods for detecting the current execution mode, such as whether the code is running under a unit test runner. Allows overriding the mode detection logic for testing or customization purposes.

public static class ModeDetector
Inheritance
ModeDetector

Remarks

This class is intended for scenarios where code behavior needs to adapt based on the execution environment, such as distinguishing between normal application runs and unit test execution. The mode detection logic can be customized by supplying an alternative implementation of the mode detector interface using the OverrideModeDetector method. Thread safety is not guaranteed; callers should ensure appropriate synchronization if accessing from multiple threads.

Methods

InUnitTestRunner()

Determines whether the current process is running within a unit test runner environment.

public static bool InUnitTestRunner()

Returns

bool

true if the current process is detected to be running under a unit test runner; otherwise, false.

Remarks

This method attempts to detect common unit test runner environments, but may return false if detection is not possible on the current platform or with certain test frameworks. The result is cached for subsequent calls.

OverrideModeDetector(IModeDetector)

Overrides the current mode detector with the specified implementation.

public static void OverrideModeDetector(IModeDetector modeDetector)

Parameters

modeDetector IModeDetector

The mode detector to use as the current implementation. Cannot be null.

Remarks

This method is typically used for testing or to customize mode detection behavior at runtime. Calling this method replaces the global mode detector instance and clears any cached detection results.