cancel
Showing results for 
Search instead for 
Did you mean: 

script assertion

New Contributor

script assertion

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.

2 REPLIES 2
Highlighted
Community Hero

Re: script assertion

Use If .. else.. if construct


Regards,
Rao.
Frequent Contributor

Re: script assertion

You could surround each assertion with a try catch.  I would wrap an assertion/try catch in simple function to minimise code duplication and aid clarity.  The following example will exercise all the test assertions, report the result, continue through all the verification and still fail the test overall.  This is known as a fail-safe test vs your fail-fast test, both have their place, it is a horses for courses thing.

 

passed = true
verify(1 == 1)
verify(1 != 1)
verify(2 == 2)
verify(2 != 2)
assert passed

def verify(def condition) {
	try {
		assert condition
	} catch (AssertionError assertion) {
		log.info assertion
		passed = false
	}
}

 

New Here?
Join us and watch the welcome video:
API Testing Mistake #2
APITestingMistake#2
Top Kudoed Authors