JUnit 不会在 Eclipse 中的断点处停止(使用 JDK 1.6.0.20)
我在 Eclipse 中的断点不会停止 JUnit 测试的执行。无论我在 JUnit 方法中的何处设置断点,它都不会阻止代码流动。将其放在 JUnit 测试中调用的类中也不起作用。
我使用的是1.6.0.20版本的JDK,所以我想我不会受到1.6.0.14版本中的bug的影响。
您知道有关此事的任何提示吗?
my breakpoints in Eclipse won't stop the execution of a JUnit test. It doesn't matter where I set the breakpoint in the JUnit method, it simply won't stop the code from flowing. Placing it in a class called in the JUnit test won't work either.
I am using the JDK in the version of 1.6.0.20, so I guess I'm not affected by the bug in version 1.6.0.14.
Do you know any hints concerning this matter?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您应该使用
Debug as > 开始单元测试JUnit测试
You should start your unit-tests with
Debug as > JUnit test
如果断点出现反斜杠,则必须转到调试透视图(窗口 → 打开透视图),然后在“断点”窗口中取消选择“跳过所有断点”按钮(带有反斜杠的圆圈)
If your break points appear with a back slash across, you have to go to the debug perspective (Window → Open perspective) and in the ‘Breakpoints’ window, unselect the ‘Skip all break points’ button (circle with backslash across)
请在调试配置中使用
> VM 参数部分
Plese use
in debug configuration > VM arguments section
我今天遇到了这个问题,对我来说,原因纯粹是愚蠢 - 如果单元测试首先向控制台输出一些内容,然后抛出异常,两者都在到达断点之前,那么您在 Eclipse 的调试角度看不到异常,因为它在 JUnit 视图中打印,但之前的输出从该视图切换到控制台输出。
I've had this problem today and for me the reason was pure stupidity – if the unit test outputs something to the console at first and throws an exception afterwards, both before reaching the breakpoint, you do not see the exception in eclipse's debug perspective because it gets printed in the JUnit view, but the output before switched away from that view to the Console output.
您的测试中可能存在错误,导致 JUnit 无法获取您尝试测试的内容。 JUnit 不喜欢显示这些错误。尝试从单元测试中删除行,直到它们开始工作,或者在单元测试调用的方法中放置断点。
There's likely an error in your test which is preventing JUnit from getting to the thing you're trying to test. JUnit doesn't like to show these errors. Try removing lines from your unit tests until they start to work, or put breakpoints inside the methods your unit test is calling.