Class TheoryAttribute
Indicates that a test method is a theory and can be run multiple times with different input data.
Inherited Members
Namespace: NUnit.Framework
Assembly: nunit.framework.dll
Syntax
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class TheoryAttribute : CombiningStrategyAttribute, IApplyToTest, ITestBuilder, IImplyFixture
Remarks
The theory attribute allows a test to be executed with a variety of data sets. For more details, please refer to the NUnit documentation.
Examples
public class SqrtTests { [DatapointSource] public double[] values = new double[] { 0.0, 1.0, -1.0, 42.0 };
[Theory]
public void SquareRootDefinition(double num)
{
Assume.That(num >= 0.0);
double sqrt = Math.Sqrt(num);
Assert.That(sqrt >= 0.0);
Assert.That(sqrt * sqrt, Is.EqualTo(num).Within(0.000001));
}
}
Constructors
View SourceTheoryAttribute(bool)
Construct the attribute, specifying a combining strategy and source of parameter data.
Declaration
public TheoryAttribute(bool searchInDeclaringTypes = false)
Parameters
Type | Name | Description |
---|---|---|
bool | searchInDeclaringTypes |