[英]Hide JUnit's stack trace when testing by creating a “new Exception()” that isn't thrown?
I am testing one of my methods w/ JUnit and the method takes an Exception
as a parameter. 我正在测试带有JUnit的方法之一,并且该方法将
Exception
作为参数。 The test looks roughly like this: 测试大致如下所示:
public void testSomething() {
...
callMethod(param1, new Exception("ignore exception"));
}
When I do this, the act of creating an Exception (not throwing it) dumps this to System.err 当我这样做时,创建异常(不抛出异常)的操作会将其转储到System.err
java.lang.Exception: ignore exception at ...testSomething at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at junit.framework.TestCase.runTest(TestCase.java:176) at junit.framework.TestCase.runBare(TestCase.java:141
java.lang.Exception:在.... testSomething处忽略异常java.lang.reflect.Method.invoke(未知源)位于junit.framework.TestCase.runTest(TestCase.java:176)at junit.framework.TestCase.runBare(TestCase.java:141)
Is there any way to suppress this output? 有什么办法可以抑制此输出? I Goggled for everything I could think of, but it picks up all sorts of unrelated stuff.
我全神贯注地想尽一切办法,但它收集了各种无关的东西。
仅供参考,函数调用在其中做了一个ex.printStackTrace()调试语句,我忘了取出它,所以亚当是正确的。
您可以在不调用父构造函数的情况下从Exception派生类吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.