は、必要に応じて等しくないdescendandノードの文字列を生成するために
public static void assertTrue(java.lang.String message,
boolean condition)
と(例えば)diff
をカスタムメッセージを渡すことができますassertTrue
のバージョン空白を無視するXML Elem
オブジェクトと比較するには、scala.xml.Utility.trim
メソッドで空白を削除することができます。
scala> val a = <foo>bar</foo>
a: scala.xml.Elem = <foo>bar</foo>
scala> val b = <foo> bar </foo>
b: scala.xml.Elem = <foo> bar </foo>
scala> a == b
res8: Boolean = false
scala> import scala.xml.Utility.trim
import scala.xml.Utility.trim
scala> trim(a) == trim(b)
res9: Boolean = true
あなたがXMLリテラルを使用する場合Scalaは属性の順序を気にしません
:
scala> val a = <foo first="1" second="2" />
a: scala.xml.Elem = <foo first="1" second="2"></foo>
scala> val b = <foo second="1" first="1" />
b: scala.xml.Elem = <foo first="1" second="1"></foo>
scala> a == b
res22: Boolean = true
私はユニットテストのためのScalaTestをお勧めしますが、あなたが持っているShouldMatchers
:
// Scala repl started with scalatest-1.2.jar in the classpath
scala> val a = <foo>bar</foo>
a: scala.xml.Elem = <foo>bar</foo>
scala> val b = <foo>bar</foo>
b: scala.xml.Elem = <foo>bar</foo>
scala> a should equal(b)
scala> val b = <foo>bar2</foo>
b: scala.xml.Elem = <foo>bar2</foo>
scala> a should equal(b)
org.scalatest.TestFailedException: <foo>bar</foo> did not equal <foo>bar2</foo>
at org.scalatest.matchers.Matchers$class.newTestFailedException(Matchers.scala:148)
at org.scalatest.matchers.ShouldMatchers$.newTestFailedException(ShouldMatchers.scala:2329)
at org.scalatest.matchers.ShouldMatchers$ShouldMethodHelper$.shouldMatcher(ShouldMatchers.scala:871)
at org.scalatest.matchers.ShouldMatchers$SeqShouldWrapper.should(ShouldMatchers.scala:1724)
at .<init>(<console>:15)
at .<clinit>(<console>)
at RequestResult$.<init>(<console>:9)
at RequestResult$.<clinit>(<console>)
at RequestResult$scala_repl_result(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.Delega...
私はassertTrueの使用を検討していました。私は 'diff'について知らなかった。私はそれを試みます。ありがとう。 – Ralph