Ask a Question

Can some one please explain why my assertion is failing

chathurad
Contributor

Can some one please explain why my assertion is failing

 

As on the image ActualschoolList and ExpectedchoolList are same.(you can see it as a log )

But when I try to assert it its giving me an error.

How to fix this.

Both variables are having somthing similar to this "[]"

 

9-19-2018 2-19-19 PM.png

2 REPLIES 2
Radford
Super Contributor

I think it is because you variable "ActualschoolList" is an empty Groovy List object, but your variable "ExpectedchoolList" is the literal string "[]" these are two different things, thus the assertion fails. If you are expecting an emty list, try defining "ExpectedchoolList" as follows:

 

def ExpectedchoolList = []

See the following page for more info on working with lists:

http://docs.groovy-lang.org/next/html/documentation/working-with-collections.html#Collections-Lists

HimanshuTayal
Community Hero

Hi @chathurad,

 

Instead of doing [] == [], match the size if you don't want to assert on the items inside your List.

 

try using 

 

assert (actualList.size() == expectedList.size()) : "Size not equal"

Click "Accept as Solution" if my answer has helped, and remember to give "kudos" 🙂

 

Regards,

Himanshu Tayal


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
cancel
Showing results for 
Search instead for 
Did you mean: