Compare scala.xml.Elem object in unit test

前端 未结 4 1904
执笔经年
执笔经年 2021-02-19 06:21

I have two scala.xml.Elem objects (actual, expected). I am using JUnit 4, but have also included XMLUnit 1.3.

Is there any easy way to compare the two objec

4条回答
  •  伪装坚强ぢ
    2021-02-19 06:54

    Use the version of assertTrue that allows passing custom messages

    public static void assertTrue(java.lang.String message,
                                  boolean condition)
    

    and (for example) diff to produce the string with the descendand nodes that aren't equal

    scala> val xml1 = johnsmith
    xml1: scala.xml.Elem = johnsmith
    
    scala> val xml2 = janesmith
    xml2: scala.xml.Elem = janesmith
    
    scala> assert(xml1 == xml2, xml1.child diff xml2.child mkString(", "))
    java.lang.AssertionError: assertion failed: john
            at scala.Predef$.assert(Predef.scala:91)
            at .(:8)
            at .()
    

提交回复
热议问题