Forum Discussion

chathurad's avatar
chathurad
Contributor
6 years ago

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 "[]"

 

2 Replies

  • Radford's avatar
    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

  • 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