Print

Test case – postconditions

When creating test cases, sometimes the need arises for some steps to be executed after a test case, for example, to remove any generated test data. And as JOSF (by default) stops any test that runs into an error during your playbook run, there is an ability to add so-called postconditions to your test cases, which always executes, regardless of the result of your test case.

Add postconditions

You can add a postcondition by pressing the + Add script postcondition button at the bottom of the test script.

After pressing the button, another area appears in which you can drop your test steps. These can vary between regular steps, to API or Database requests and even entire Page actions to leverage reusability of your actions, just like you are used to with the regular test script. The only difference is, that these steps will get executed no matter the outcome of the steps in the test script section.

Postcondition results

By default, results of the steps in the postcondition section do not affect test case results. If your test ran fine, but steps in your postcondition failed, the test will still be marked PASS in the playbook report, however the playbook report and the CLI result table will report a warning that steps in your postcondition failed.

To change the behavior of impact on the test result, toggle on the “Fail test case postcondition on failure” option. If enabled, this results in one of the following situations;

  • If your test ran successfully (not failing), but your postcondition failed, your test will be marked as a fail, and the report will warn that the test failed because of a step in your postcondition.
  • If your test failed and your postcondition also failed, the test case will be marked as a fail and the report will warn that the postcondition also failed.

And again, if your post condition fails, regardless of the option enabled, the report will always inform you that it failed.

The following images show the different conditions of what effect a postcondition can have on a test case.

Passed although postcondition failed
Passed although postcondition failed
Failed because of postcondition, with corresponding option checked
Failed because of postcondition, with corresponding option checked
Failed testcase and still executed postcondition
Failed testcase and still executed postcondition
In this document