Adding Conditions to Control When Tests Run

There can be times when you want a test or a group of tests to only run when certain criteria are met. As an example, you may want to set a condition that will bypass the memory programming step if any of the preceding tests failed.

Conditions are represented in the test list by a question-mark as shown in Figure 16. The condition is evaluated just before the group or test is due to be executed, and the tests are only performed if the condition evaluates to TRUE.

Conditions are indicated by a question mark

Figure 16: Conditions that Control When Tests Run

In the example above, the nested conditions Verify Programmed Data and Full Program Required will only be evaluated if the Program Flash condition at the top of the hierarchy is TRUE.

To set a condition:

  1. Go to the XJRunner Setup screen
  2. Select the test or test group from the test list (see Figure 17)
  3. Click Add Condition... to open the Add Condition dialog box
  4. Enter a condition as described below
  5. Click OK in the Add Condition dialog box
  6. Save the project
Select the test or test group on which to apply the condition Click Add Condition...

Figure 17: Adding a Condition for When a Test Runs

Entering a Condition

The condition is created in the Add Condition dialog by a mix of typing and inserting global functions and/or the results of previous tests:

Provide a unique name The condition is created in this text box To insert a global variable into the expression, click Insert Global To use the result of a previous test in the expression, click Insert Test Function

Figure 18: Creating a Condition

Creating Expressions Based on the Result of a Previous Test

Functions related to the result of a previous test can be inserted into the condition by clicking Insert Test Function. This opens the dialog box shown in Figure 19. For example, to insert HAS_PASSED("XJDemo.IC11.IIC_CheckPresent") into the condition, select the test IC11.IIC_CheckPresent from the list, select the Pass radio button, and click OK.

Select the test that returns the result to be used in the expression Creates a condition that checks the selected test ran Creates a condition that checks the selected test failed Creates a condition that checks the selected test passed Creates a condition that depends on the value returned by the selected test

Figure 19: Using the Result from a Previous Test in a Condition

However, it is important to ensure you do not attempt to evaluate the result of a previous test if that previous test did not run; otherwise, a runtime error would occur. It is therefore good practice only to use the result of another test in conjunction with a function that ensures the test executed, such as HAS_RUN(). This can be done by combining the two expressions using a Boolean operator as described next.

The most commonly used Boolean operator is a short-circuiting logical AND, represented by &&?. If the first part of the expression evaluates to FALSE, the second part is not evaluated.

Short circuiting operators are useful when combining functions such as HAS_PASSED() with HAS_RUN() because they can avoid both halves of the expression being evaluated. For example, the condition:
HAS_RUN(test) &&? HAS_PASSED(test)
does not attempt to evaluate HAS_PASSED(test) if the test has not run (i.e. if HAS_RUN(test) returns FALSE). This prevents a runtime error.

The HAS_PASSED() operator can also be used to avoid running a test that it is already known will fail. Consider an example from the test list above (Figure 17): the test group that functionally checks an I2C ADC includes a test to confirm it responds to its address on the I2C bus and another that takes a reading from one of its ADC channels. Because there is no point in attempting to read a value from the device if it is not responding, it is sensible to add a condition to the second test that ensures it only runs if the bus check passed. This is done using the following expression:
HAS_RUN("XJDemo.IC11.IIC_CheckPresent") &&? HAS_PASSED("XJDemo.IC11.IIC_CheckPresent")

  • The Boolean AND and OR operators && and || should not be used when setting up conditions because they are not short-circuiting in XJEase and therefore carry the risk of causing run-time errors.

Creating Expressions with Global Variables

Global variables (both built-in and those from circuit code files) can also be used in a condition. They are inserted using the Insert Global button (Figure 18 above).

XJEase has a built-in global called TEST_FAIL_COUNT that is updated after every test is run and is only zero if all tests have passed. It can be used, for instance, to avoid trying to program firmware if any of the preceding tests have failed. In that example, the condition used for the programming test would be: TEST_FAIL_COUNT = 0.

Continuing After a Test Failure

By default, if a test fails, XJRunner is set to stop at that point rather than continuing through the test list. However, if you are using conditions that will stop tests executing that you wouldn't want to run on a faulty board (e.g. to stop a failing board from being programmed), it is recommended that you override the default. Allowing testing to continue after a failure in this situation can be beneficial because the additional testing might provide useful insights into the cause of the failure, and the conditions will prevent unwanted tests from running. When a condition is added, you will therefore be asked if you would like to override the default setting by enabling Continue on Test Failure.