Table of Contents

Class PropertyAttribute

Namespace
Conjecture.MSTest
Assembly
Conjecture.MSTest.dll

Marks a method as a Conjecture property-based test (MSTest).

[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public sealed class PropertyAttribute : TestMethodAttribute
Inheritance
TestMethodAttribute
PropertyAttribute
Inherited Members
TestMethodAttribute.DisplayName
TestMethodAttribute.UnfoldingStrategy
TestMethodAttribute.DeclaringFilePath
TestMethodAttribute.DeclaringLineNumber

Remarks

  • When using other attributes like Microsoft.VisualStudio.TestTools.UnitTesting.DataRowAttribute or Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataAttribute, the use of Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute is still required.
  • Test methods must be:
    • public, or if Microsoft.VisualStudio.TestTools.UnitTesting.DiscoverInternalsAttribute is used then it can be internal.
    • not static
    • not generic
    • not abstract
    • return type is either void, Task, or ValueTask. If void, then it shouldn't be async.

Constructors

PropertyAttribute(string, int)

Marks a method as a Conjecture property-based test (MSTest).

public PropertyAttribute(string sourceFile = "", int sourceLine = -1)

Parameters

sourceFile string
sourceLine int

Properties

DeadlineMs

Deadline for each test run in milliseconds. 0 means no deadline.

public int DeadlineMs { get; set; }

Property Value

int

MaxExamples

Maximum number of examples to generate. Defaults to 100.

public int MaxExamples { get; set; }

Property Value

int

MaxStrategyRejections

Maximum number of times a strategy may reject a value. Defaults to 5.

public int MaxStrategyRejections { get; set; }

Property Value

int

Seed

Optional fixed seed for deterministic runs. 0 means use a random seed.

public ulong Seed { get; set; }

Property Value

ulong

Targeting

Whether to run a targeting phase after generation. Defaults to true.

public bool Targeting { get; set; }

Property Value

bool

TargetingProportion

Fraction of MaxExamples budget allocated to the targeting phase. Defaults to 0.5.

public double TargetingProportion { get; set; }

Property Value

double

UseDatabase

Whether to use the example database. Defaults to true.

public bool UseDatabase { get; set; }

Property Value

bool

Methods

ExecuteAsync(ITestMethod)

Executes a test method.

[RequiresDynamicCode("Property test execution uses MakeGenericMethod for typed strategy dispatch.")]
[RequiresUnreferencedCode("Property test execution accesses parameter type metadata that may be trimmed.")]
public override Task<TestResult[]> ExecuteAsync(ITestMethod testMethod)

Parameters

testMethod ITestMethod

The test method to execute.

Returns

Task<TestResult[]>

An array of TestResult objects that represent the outcome(s) of the test.

Remarks

Extensions can override this method to customize running a TestMethod.