cancel
Showing results for 
Search instead for 
Did you mean: 

Assertion using groovy sometimes throws java.lang,NullPointerException

Highlighted
Frequent Contributor

Assertion using groovy sometimes throws java.lang,NullPointerException

Hi,

when i try to assert a group assertion like:

assert slurperresponse.values.data.name.person== true
assert slurperresponse.values.data.address.person== true
assert slurperresponse.values.data.car.person== true
assert slurperresponse.values.data.city.person== true
assert slurperresponse.values.data.country.person== true
assert slurperresponse.values.data.province.person== true
assert slurperresponse.values.data.code.person== true
assert slurperresponse.values.data.group.person== true

It works for sometime.

After sometime it throws java.lang.NullPointerException saying java.lang.NullPointerException:Cannot get person on null object.

If i remove the last assertion it works again.

i tried this:

if(slurperresponse.values.data.group.person != null){

assert slurperresponse.values.data.group.person== true

}

i got the same error.

If i wait for sometime then it works.

 

Is there a probleme with memory leak or garbage collection .

Did someone notice this behavior ?

Or is there a better way to reduce all lines?

Thank you

 

7 REPLIES 7
Highlighted
Community Hero

Re: Assertion using groovy sometimes throws java.lang,NullPointerException

Difficult to say.
Try couple of times and see.

One question is the value boolean? or some name?


Regards,
Rao.
Highlighted
Frequent Contributor

Re: Assertion using groovy sometimes throws java.lang,NullPointerException

Yes i tried couple of time and the result is same:

it works sometime then it fails at this moment the variable is null.

cannot figure out how it's possible.

The value is a name because it retrieve from json response as string and store it in project level properties.

 

Highlighted
Community Hero

Re: Assertion using groovy sometimes throws java.lang,NullPointerException

Are you running the assertion without running the step?


Regards,
Rao.
Highlighted
Frequent Contributor

Re: Assertion using groovy sometimes throws java.lang,NullPointerException

The assertion is part of a method.

i'm calling from another testsuite.

Community Hero

Re: Assertion using groovy sometimes throws java.lang,NullPointerException

Thumb rule is to have each and every test case be independent.

There might be something incorrect in the usage in your case. If you want to re-use code, use script library as suggested in the other thread.


Regards,
Rao.
Highlighted
Frequent Contributor

Re: Assertion using groovy sometimes throws java.lang,NullPointerException

@nmrao 

Hi,

there is nothing incorrect in my code.

i'm using library. i did not put the library setcion in my post.

Highlighted
Community Hero

Re: Assertion using groovy sometimes throws java.lang,NullPointerException

Sorry it was nowhere mentioned incorrect in your code.


Regards,
Rao.