1

i need to validate many assertions in same script assertion. But when any one of assert fails, runner stops there itself and control passed to next step. Below is my case

assert (1 ==1);
log.info "1";
assert (1 == 2);
log.info "2";
assert (1 ==3);
log.info "3";

When i execute the above, 2nd assertion fails and third assertion did not executed at all. Is there is any way to validate all assertions.

Sidharth
  • 27
  • 7
  • Does [disabling "fail on error"](https://stackoverflow.com/questions/16341547/continue-after-failed-assertion) solve the problem? – jsheeran Apr 08 '19 at 07:57
  • in my case, I want to run the codes available after a failed assertion. "Fail on error" option works on step level. – Sidharth Apr 08 '19 at 13:34

2 Answers2

1

Something like this could work:

java.util.ArrayList<String> failedAssertions = new java.util.ArrayList<String>()
def allAssertionsPassed = true
if (!1==1) {
    failedAssertions.add("1==1")
    allAssertionsPassed = false
}
if (!1==2) {
    failedAssertions.add("1==2")
    allAssertionsPassed = false
}
if (!1==3) {
    failedAssertions.add("1==3")
    allAssertionsPassed = false
}

if (!allAssertionsPassed ) {
    log.info "Failed assertions:"
    for (def s : failedAssertions) {
        log.info s
    }
}
assert(allAssertionsPassed)
Steen
  • 853
  • 5
  • 12
  • You can probably improve on this, by creating an ArrayList of the assertions themselves as strings, and then evaluate and execute these in a loop. You can then reuse the same ArrayList when logging. – Steen Apr 08 '19 at 07:58
1

As usual, Steen has submitted a good answer (up-voted).

In my test suites, I have some tests where I want SoapUI to stop where there is a fail (e.g. assert). I have other tests where I want the test to continue where there is fail. To implement this, I usually have some Groovy script to do the result check. E.g. Pass/Fail. I then use a data-sink step to record each test's details with the result. I can then view the results in Excel for test reporting.

Chris Adams
  • 1,376
  • 1
  • 8
  • 15