Assembly: Gallio (in Gallio.dll) Version: 3.2.0.0 (3.2.356.0)
Syntax
| C# |
|---|
public static class TestStep |
| Visual Basic (Declaration) |
|---|
Public NotInheritable Class TestStep |
Remarks
A step is a delimited region of a test. Each step appears in the report as if it were a dynamically generated test nested within the body of the test (or some other step) that spawned it. The step has its own execution log, pass/fail/inconclusive result and in all other respects behaves much like an ordinary test would.
The number of steps within a test does not need to be known ahead of time. This can be useful in situations where insufficient information is known about the internal structure of a test to be able to fully populate the test tree will all of its details. Because steps are dynamically generated at runtime, they appear in test reports but they are invisible to test runners. that traverse the test tree.
There are many interesting uses for steps. For example:
- A single test consisting of a long sequence of actions can be subdivided into steps to simplify analysis.
- A test might depend on environmental configuration that cannot be known a priori.
- A performance test might be scheduled to run for a certain duration but the total number of iterations is unknown. By running each iteration as a step within a single test, the test report can display the execution log and pass/fail result of each iteration independently of the others.
- A script-driven test driver could execute a scripted sequence of verification commands as a distinct step. If the script is written in a general purpose programming language, the total number of commands and the order in which they will be performed might not be known ahead of time. Using steps enables the integration of tests written in forms that cannot be directly adapted to the framework's native testing primitives.
- When testing non-deterministic algorithms, it is sometimes useful to repeat a test multiple times under slightly different conditions until a certain level of confidence is reached. The variety of conditions tested might be determined adaptively based on an error estimation metric. Using steps each condition verified can be reported independently.
Examples
Running as many iterations of a test as possible for a set maximum duration.
Each iteration will run as a separate test step so that it has its own test
execution log and test outcome included in the test report.
CopyC#[TestFixture]
public class Fixture
{
[Test]
public void MeasurePerformance()
{
// Warm up.
TestStep.RunStepAndVerify("Warm Up", DoSomething, TestOutcome.Passed);
// Run as many iterations as possible for 10 seconds.
int iterations = 0;
Stopwatch stopwatch = Stopwatch.StartNew();
while (stopwatch.ElapsedMilliseconds < 10000)
{
iterations += 1;
TestStep.RunStepAndVerify("Iteration #" + i, DoSomething, TestOutcome.Passed);
}
double iterationsPerSecond = iterations * 1000.0 / stopwatch.ElapsedMilliseconds;
Assert.GreaterEqualThan(iterationsPerSecond, 5, "Unacceptable performance.");
}
private void DoSomething()
{
objectUnderTest.Wibble();
}
}
