How Does the Status Expression Work in TestStand?

Updated Sep 22, 2020

Environment

Software

  • TestStand

This tutorial gives you a better view of how the status expression works in TestStand.

For a step in TestStand, the Status Expression sets the value of the property Step.Result.Status. This property is a string type and defines the overall step status during test execution. By default, TestStand can assign the following values to the Status Expression: "Done", "Skipped", "Passed", "Failed", and "Error", but you can specify any string to this property.
 

To modify the Status Expression for a step, click on the step in the Steps Pane, and look at the Step Settings Pane below. Ensure that the Properties tab is selected, and then click on the Expressions list item as shown:

 

The Status Expression field, like all other TestStand expression fields, can accept multiple expressions separated by commas. Note that if multiple expressions are used, the result of the last expression will be assigned to Step.Result.Status. Remember that Step.Result.Status is a string value—if the last expression does not evaluate to a string, an error will occur.
 

Let’s look at what TestStand does with the Status Expression field behind the scenes. Take the following example:

 

 

TestStand will take the contents of the Status Expression field and perform the following assignment:

Step.Result.Status = Evaluate(“Locals.x == Locals.y ? \"Passed\" : \"Failed\"”)

Notice the addition of backslashes before the inside quotation marks. Evaluate( exprString ) takes a string type input, and the backslashes (or escape characters) preceding the inside quotation marks ensure that the quotation characters are part of the string without prematurely ending it.

 

Test step types, such as the Pass/Fail Test, will include an un-editable Status Expression:



This is a good example of multiple expressions being used in the Status Expressions field. The first expression will set the step's PassFail property equal to its DataSource property:

Step.DataSource != "Step.Result.PassFail" ? Step.Result.PassFail = Evaluate(Step.DataSource) : False

The next expression, which is the last to be evaluated sequentially, will evaluate to a string of either “Passed” or “Failed". TestStand will internally evaluate that expression like this:

Step.Result.Status = Evaluate(“Step.Result.PassFail ? \"Passed\" : \"Failed\"”)

Note: As seen in the examples above, the conditional expression operator, ? :, is often used in the Status Expression. Take a look at the Expression Operators section of the TestStand manual for more information on this.