Forum Discussion

chathurad's avatar
6 years ago

Why my assertion is failing

As on the image you can see Mylist and CityList are same.

But at the assertion get failed.

3 Replies

  • try to compare single item at once, hope you will find the error that way.



    • JHunt's avatar
      Community Hero

      Use in only to compare single items from a list. Use equals to compare the whole list, or assert that each item from the first list is in the second list.


      def a = [1,2]
      def b = [1,2,3]
      def c = [[1,2],3]
      def d = [1,2]
      assert (a in c)
      assert !(a in b)
      a.each { assert it in b }
      assert a == d
  • I was able to solve this issue by adding below aseertion.

  myList cityList
    assert myList == cityList
    assert cityList.equals(myList)