我在junit中遇到此错误,该测试的期望值为NullPointerException,而期望值为NullPointerException,但是却得到了RuntimeException。
奇怪的是RuntimeException 的原因是 NullPointerException。为什么不会被检测到的原因有哪些?对于仅由测试框架捕获的顶级异常,这是预期的行为吗?如果是这样,我该如何解决?
[junit] Testcase: testNullValueInField(com.mypackage.translation.SomeTest): Caused an ERROR
[junit] Unexpected exception, expected<java.lang.NullPointerException> but was<java.lang.RuntimeException>
[junit] java.lang.Exception: Unexpected exception, expected<java.lang.NullPointerException> but was<java.lang.RuntimeException>
[junit] Caused by: java.lang.RuntimeException: Failed to deserialize data to class '<myclasshere>'.
[junit] at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
[junit] at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
[junit] at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
[junit] at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
[junit] at java.util.stream.Streams$StreamBuilderImpl.forEachRemaining(Streams.java:419)
[junit] at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
[junit] at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
[junit] at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
[junit] at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
[junit] at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
[junit] at org.jooq.lambda.SeqImpl.collect(SeqImpl.java:189)
...
[junit] at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:277)
[junit] at com.fasterxml.jackson.databind.deser.SettableBeanProperty._throwAsIOE(SettableBeanProperty.java:551)
[junit] at com.fasterxml.jackson.databind.deser.SettableBeanProperty._throwAsIOE(SettableBeanProperty.java:532)
[junit] at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:108)
[junit] at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:276)
[junit] at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:140)
[junit] at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3814)
[junit] Caused by: java.lang.NullPointerException
[junit] at com.<mypackage>.(<myclass>.java:72)
[junit] at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:106)