这是我的测试用例
case class WithDefaultValueHolder(values: Seq[WithDefaultValue])
case class WithDefaultValue(name: String, gender: String = "male")
it("default with valid json"){
val res = WithDefaultValueHolder(Seq(WithDefaultValue("Bob")))
parse("""{"values":[{"name":"Bob","gender":"male"}]}""").extract[WithDefaultValueHolder](
DefaultFormats, Manifest.classType(classOf[WithDefaultValueHolder])) shouldBe (res)
}
下面的测试也通过了,它认为格式错误的json是默认值的有效json。为什么?如何限制这种行为。如何在测试用例下失败?
it("default with invalid json"){
val res = WithDefaultValueHolder(Seq(WithDefaultValue("Bob")))
parse("""{"values":[{"name":"Bob","xyz":"abc"}]}""").extract[WithDefaultValueHolder](
DefaultFormats, Manifest.classType(classOf[WithDefaultValueHolder])) shouldBe (res)
}