ExecutableConditionAttribute Class

Definition

This attribute is used to conditionally control whether a test class or a test method will run or be ignored, based on whether a given executable (tool) is available.

[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Method, AllowMultiple=true, Inherited=false)]
public sealed class ExecutableConditionAttribute : Microsoft.VisualStudio.TestTools.UnitTesting.ConditionBaseAttribute
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Method, AllowMultiple=true, Inherited=false)]
[System.Runtime.CompilerServices.Nullable(0)]
public sealed class ExecutableConditionAttribute : Microsoft.VisualStudio.TestTools.UnitTesting.ConditionBaseAttribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Method, AllowMultiple=true, Inherited=false)>]
type ExecutableConditionAttribute = class
    inherit ConditionBaseAttribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Method, AllowMultiple=true, Inherited=false)>]
[<System.Runtime.CompilerServices.Nullable(0)>]
type ExecutableConditionAttribute = class
    inherit ConditionBaseAttribute
Public NotInheritable Class ExecutableConditionAttribute
Inherits ConditionBaseAttribute
Inheritance
ExecutableConditionAttribute
Attributes

Remarks

This is a generic, tool-agnostic condition. There are two modes:

  • When no Arguments are supplied, the condition only checks that the executable is discoverable on the system PATH (and, on Windows, resolvable through PATHEXT). It does not run the executable. For example, it can verify that docker is installed.
  • When Arguments are supplied, the condition runs executable arguments and is met only when the process exits with code 0 within TimeoutSeconds. For example, [ExecutableCondition("docker", "version")] verifies that the Docker CLI actually responds. The process output is redirected and discarded, and the process (together with its child process tree, where the runtime supports it) is terminated if it exceeds the timeout.

Product-specific state (for example whether the Docker daemon is configured for Linux containers) is intentionally out of scope; layer such checks on top of this attribute or author your own ConditionBaseAttribute.

Each distinct executable-and-arguments combination forms its own condition group (see GroupName). As a result, applying the attribute multiple times with different commands requires all of them to be satisfied (logical AND), while applying it multiple times with the same command requires only one to match (logical OR).

This attribute isn't inherited. Applying it to a base class will not affect derived classes.

Constructors

Name Description
ExecutableConditionAttribute(ConditionMode, String, String[])

Initializes a new instance of the ExecutableConditionAttribute class.

ExecutableConditionAttribute(ConditionMode, String)

Initializes a new instance of the ExecutableConditionAttribute class that checks whether the given executable is available on PATH.

ExecutableConditionAttribute(String, String[])

Initializes a new instance of the ExecutableConditionAttribute class that includes the test only when the given command is available.

ExecutableConditionAttribute(String)

Initializes a new instance of the ExecutableConditionAttribute class that includes the test only when the given executable is available on PATH.

Properties

Name Description
Arguments

Gets the arguments passed to the executable. When empty, only the presence of the executable on PATH is checked; otherwise the executable is run with these arguments and must exit with code 0.

Executable

Gets the executable that this condition looks for.

GroupName

Gets the group name for this attribute. Each command -- combined with Mode -- forms its own group, so requiring several different commands is combined with a logical AND, while the same command with opposite modes does not silently cancel out (mirroring MemberConditionAttribute).

IgnoreMessage

Gets or sets the ignore message indicating the reason for ignoring the test method or test class.

(Inherited from ConditionBaseAttribute)
IsConditionMet

Gets a value indicating whether the condition is met. The implementation of this property shouldn't read the Mode property.

Mode

Gets the condition mode.

(Inherited from ConditionBaseAttribute)
TimeoutSeconds

Gets or sets the maximum number of seconds to wait for the executable to exit when Arguments are provided. A value less than or equal to 0 means no timeout. The default is 30 seconds.

Applies to