Ask a Question

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

SOLVED
dedmunds
New Contributor

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?

2 REPLIES 2
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
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta

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!

cancel
Showing results for 
Search instead for 
Did you mean: