简体   繁体   English

JUnit Eclipse - 成功显示堆栈跟踪

[英]JUnit Eclipse - Display stack trace on success

I'm writing some unit tests in eclipse which expect exceptions to be thrown. 我正在eclipse中编写一些单元测试,期望抛出异常。

I wonder if there is an option to display the stack-trace when a test passes, it would be useful when you are writing test for the first time to check if the exception is been thrown really due to the case you are testing. 我想知道是否有一个选项可以在测试通过时显示堆栈跟踪,当你第一次编写测试时检查是否真的因为你正在测试的情况而抛出异常会很有用。

thanks! 谢谢!

You shouldn't need to do that. 你不应该这样做。

Use the @Test annotation with an expected argument: @Test注释与expected参数一起使用:

@Test(expected=MyAppException.class)

If the test does not throw the exception it's a test failure. 如果测试没有抛出异常,那就是测试失败。

There should be an Eclipse view option to show test logging output, but in general, explicit logging from tests isn't valuable. 应该有一个Eclipse视图选项来显示测试日志记录输出,但通常,从测试中显式记录是没有价值的。 You can also debug your test if you don't trust the JUnit annotations. 如果您不信任JUnit注释,也可以调试测试。

Why not put System.out.print() statements inside the catch block of the test? 为什么不将System.out.print()语句放在测试的catch块中? I'm not sure how else you want to display output from a test because they are typically built to be silent when they succeed since there are so many of them. 我不确定你想要如何显示测试的输出,因为它们通常被构建为在成功时保持沉默,因为它们有很多。

Have you thought about using log4j and log.debug()? 你有没有想过使用log4j和log.debug()?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM