Search code examples
functionmethodsgroovyready-api

How do i assert in groovy with multple scenarios?


I am testing an API using ReadyAPI and currently I am trying to figure some solution for the following situation:

I run 3 request in parallel that can affect the way they respond. The test is to add an object to a list and get errors on the other two lists and the item should be added to only one of them.

So far so good. but when running in parallel, the status codes modifi: Ex: First run: Test 1 - 200 Test 2 - 400 Test 3 - 400 Cleanup

Second run: Test 1 -400 Test 2 -200 Test 3 -400 Cleanup

Possibly 3rd run: (it isn't a predictable situation) Test 1 - 200 Test 2 - 200 Test 3 - 400

The only way i thought of so far is to create a groovy assertion function so that it can assert and return the current statuses and to asset that 3rd run is exposed. Bear in mind that it is not always the third run that can generate this result. Any ideeas on how that function should work?

def A = 200
def B = 400
def C = 400

def assesmentFunct(a, b,c){
assert a = a
assert b = b
assert c = c
}

assesmentFunct(A,B,C)

The thig is that i can have 3 scenarios where 200 is possible so i am thinking of some kind of matrix of assetions Please help

Tried if else nessted, switch-case


Solution

  • collect results into an array and assert the array

    def results = [200,400,400]
    
    assert results in [
        [400,400,200],
        [400,200,400],
        [200,400,400]
    ]