Forum Discussion

dedmunds's avatar
dedmunds
New Contributor
5 years ago

Is there a way to exit a test case when the first step fails?

I'm creating tests for an API that updates an existing DB2 row.  The first step of the test is a DataSource with an SQL query to select a specific row to update.  For example, I may want to test what happens when the API updates rows where timeOfDay='1200'.  However, there are times when there are no rows on the database that match the criteria, so the DataSource does not find any data to use in the test, the API request fails, and the test case fails.  Instead, I want to exit (or pass) the test without recording a failure.

 

I've tried playing around with the "Fail on Empty" and "Skip Loop on Empty" options, but I haven't been able to get them to do what I need.  Is there a way to skip or pass a test case when the first step fails?

  • I added the JDBC count step and a groovy script with a conditional "testRunner.gotoStepByName", and it looks like it's working the way I want.  Thanks for the help!

  • richie's avatar
    richie
    Community Hero
    Hey dedmunds,

    Theres lots of ways to do this. The easiest i suggest is adding 2 new test steps at the start of your test case.

    First new test step is JDBC step: select count(*) from table;
    Second new test step would be the Conditional GoTo step which uses XPATH and set this to jump to the final step in test (that could be a placeholder cos the goto step doesnt support jumping to adifferent testcase) IF zero rows were returned in first JDBC step or jump to next test case (skipping all other steps in test)

    OR

    Add 2 new test steps at the start of your test case.

    First new test step is JDBC step: select count(*) from table;
    Second new test step is Groovy step with conditional goto like "if jdbc response is zero rows, jump to next testcase (skipping all other steps in testcase), else jump to next JDBC step (which was the original first step).

    As im sitting here other ways of doing this are popping in my head. Im sure the other forum members will have various other options

    Cheers

    Rich
    • dedmunds's avatar
      dedmunds
      New Contributor

      I added the JDBC count step and a groovy script with a conditional "testRunner.gotoStepByName", and it looks like it's working the way I want.  Thanks for the help!