使用JUnit运行测试用例时,在Eclipse Debug中禁用Drop to Frame功能 [英] Drop to frame feature disabled in Eclipse Debug while running testcases using JUnit

查看:144
本文介绍了使用JUnit运行测试用例时,在Eclipse Debug中禁用Drop to Frame功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

环境:
Linux,Eclipse Juno,Java 7,JUnit



当一个简单的应用程序(具有main方法的java类)在调试模式下运行时,Drop to Frame功能在Eclipse中运行正常。但是,如果从junit测试用例调用相同的方法,则在Eclipse中禁用Drop to Frame功能。从文档


注意,此命令仅在当前虚拟机支持删除到
框时可用,而选定的堆栈不是顶部框架或
本机方法中的框架。


从Debug窗口中的堆栈框架中可以看出junit测试用例运行,有一个'NativeMethodAccessorImpl.invoke'是一个本机的框架。我假设这是Drop to Frame被禁用的原因。



让我知道这个推理是否正确,如果是,任何解决方法可以克服这个

解决方案

我在Windows下使用Eclipse Luna,Java 7。
情况仍然如下所述:对于紧随NativeMethodAccessorImpl.invoke框架的测试方法,Drop to frame被禁用。
drop to frame的禁用状态绑定到方法 canDropToFrame() supports supportsDropToFrame()在类 org.eclipse.jdt.internal.debug.core.model.JDIStackFrame
(在我的发行版)部分插件/org.eclipse.jdt.debug_3.8.102.v20150115-1323/jdimodel.jar
方法supportsDropToFrame()检查是否可以删除特定的框架,并测试


  1. JVM必须支持丢帧
  2. 框架不能是最顶层框架
  3. 框架不能是本地的
  4. 以前的框架不能是原生的

所以Ramesh的假设是对的。
这是测试3 + 4的原始代码片段:

  int index = 0; 
JDIStackFrame frame = null;
while(index< frames.size()){
frame =(JDIStackFrame)frames.get(index);
index ++;
if(frame.isNative()){
return false;
}
if(frame.equals(this)){
if(jdkSupport){
// JDK 1.4 VMs目前无法弹出
//框直接在本机框架上方
if(index< frames.size()
&&((JDIStackFrame)frames.get(index))
.isNative()){
返回false;
}
}
返回true;
}
}

该评论表明它是用JDK 1.4次,所以也许JVM现在也可以在本机框架之上放置框架。



我创建了一个修补版本的JDIStackFrame,它跳过测试4.
现在当在Junit测试方法中暂停时,按照预期的方式启用Drop to frame。



但是,当实际丢弃帧时,我收到一条错误消息框,其中指出
com.sun.jdi.InternalException:回复中有错误代码:32发生了弹出框架框架。

我假设这是一个JDWP错误代码。
因此,似乎这样一个Drop to frame在JDK 1.7中不起作用(不了解1.8),而不是Eclipse的事情。


Environment: Linux, Eclipse Juno, Java 7, JUnit

When a simple application (a java class with main method) is run in debug mode, 'Drop to Frame' feature works fine in Eclipse. However if the same method is invoked from a junit test case, 'Drop to Frame' feature is disabled in Eclipse. From the documentation

Note this command is only available if the current VM supports drop to frame and the selected stackframe is not the top frame or a frame in a native method.

As we can see from the stack frames in Debug window when a junit test case is run, there is a frame 'NativeMethodAccessorImpl.invoke' which is native. I'm assuming this is the reason for 'Drop to Frame' being disabled.

Let me know if this reasoning is correct and if yes, any workarounds available to overcome this.

解决方案

I use Eclipse Luna, Java 7 under Windows. The situation is still as described: "Drop to frame" is disabled for the test method which immediately follows the 'NativeMethodAccessorImpl.invoke' frame. The disabled state of the "Drop to frame" is bound to method canDropToFrame() respective supportsDropToFrame() in class org.eclipse.jdt.internal.debug.core.model.JDIStackFrame, (in my distribution) part of plugins/org.eclipse.jdt.debug_3.8.102.v20150115-1323/jdimodel.jar. Method supportsDropToFrame() checks if a specific frame can be dropped, and tests

  1. the JVM must support to drop frames
  2. the frame must not be the top most frame
  3. the frame must not be native
  4. the prior frame must not native

So the assumption of Ramesh was right. This is the original code snippet for tests 3 + 4:

int index = 0;
JDIStackFrame frame = null;
while (index < frames.size()) {
    frame = (JDIStackFrame) frames.get(index);
    index++;
    if (frame.isNative()) {
        return false;
    }
    if (frame.equals(this)) {
        if (jdkSupport) {
            // JDK 1.4 VMs are currently unable to pop the
            // frame directly above a native frame
            if (index < frames.size()
                    && ((JDIStackFrame) frames.get(index))
                            .isNative()) {
                return false;
            }
        }
        return true;
    }
}

The comment suggests that it was written in JDK 1.4 times, so maybe in the meantime the JVM can now also drop frames above native frames.

I created a patched version of JDIStackFrame, which skips test 4. Now when pausing in a Junit test method, "Drop to frame" was enabled, as expected.

But when actually dropping the frame, I received an error message box which stated "com.sun.jdi.InternalException: Got error code in reply: 32 occurred popping stack frame".

I assume that this is a JDWP error code. Therefore it seems that such a "Drop to frame" does not work in JDK 1.7 (don't know about 1.8), and it's not a Eclipse thing.

这篇关于使用JUnit运行测试用例时,在Eclipse Debug中禁用Drop to Frame功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆