本文介绍了JUnit:可能“期望”一个包装的异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道可以在JUnit中定义一个'expected'异常:

I know that one can define an 'expected' exception in JUnit, doing:

@Test(expect=MyException.class)
public void someMethod() { ... }

但是如果总是有相同的异常抛出,但是使用不同的嵌套
原因

But what if there is always same exception thrown, but with different 'nested'causes.

任何建议? / p>

Any suggestions?

推荐答案

您可以将测试代码包装在try / catch块中,捕获抛出的异常,检查内部原因,log / assert /任何,然后重新抛出异常(如果需要)。

You could wrap the testing code in a try / catch block, catch the thrown exception, check the internal cause, log / assert / whatever, and then rethrow the exception (if desired).

这篇关于JUnit:可能“期望”一个包装的异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 04:50