Java Eclipse 中 JUnit 测试的调试断点不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1507252/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 13:36:20  来源:igfitidea点击:

Debugging breakpoints on JUnit test in Eclipse are not working

javaeclipsedebuggingjunit

提问by tekumara

I am trying to debug a junit test in eclipse but my breakpoints are not firing (unless they are on the first or second line).

我正在尝试在 Eclipse 中调试 junit 测试,但我的断点没有触发(除非它们在第一行或第二行)。

I've tried deleting and recreating all breakpoints in the workspace, cleaning the project, creating a new debug configuration, and running the test method individually and as part of a test class with other methods. But all to no avail :-(

我尝试删除并重新创建工作区中的所有断点,清理项目,创建新的调试配置,并单独运行测试方法并作为测试类的一部分与其他方法一起运行。但一切都无济于事:-(

 public void testLoadPatientsAndConvertToBeans() throws IOException, CDataGridException {
  File file = fileutil.getFileFromPrefsOrPrompt(basefileDef);

  CDataBuilder builder = new CDataDelimitedFileBuilder(file, 
    CDataDelimitedFileBuilder.DelimiterSettings.WINDOWS_CSV,
    basefileDef);

  // breakpoints placed on lines from here on do not fire

  CDataCacheContainer container = 
   cacheIO.construct(
     new CDataNarrower(
       cacheIO.construct(builder)
     ).setConvertMissing(true));

  assertEquals(13548, container.size());

  cacheIO.export(container, patients);

  Collection<Patient> pBeans = patients.getBeans();

  assertEquals(container.size(), pBeans.size());

  Patient patient = pBeans.iterator().next();
  Map props = patient.getPropertyMap();

  System.out.println(props);
 }

采纳答案by Vineet Reynolds

This is likely if you are using Sun JDK 6 Update 14. See another similar SO question here. The likely resolution in such a case is to use Sun JDK 6 Update 16.

如果您使用的是 Sun JDK 6 Update 14,则可能会出现这种情况。请在此处查看另一个类似的 SO 问题。在这种情况下,可能的解决方案是使用 Sun JDK 6 Update 16。

回答by Oscar Chan

My first intuition is that the cached class in eclipse is out of sync with your codes. However, given you have tried clean/rebuild your project, it should have fixed it. As you can put a breakpoint on the 1st/2nd line, what happens when you step through the codes? Does the code align with each steps? If not, it shows that the eclipse has a different version of class from your source codes. If they are the same, I would try to down a newer copy of eclipse (I assumed you have already tried restart your eclipse) since you may have discovered a strange bug (new version may have fixed it or clean some stale data). Sorry that I can't be any more helpful.

我的第一个直觉是 eclipse 中的缓存类与您的代码不同步。但是,鉴于您已尝试清理/重建项目,它应该已修复它。由于您可以在第 1 行/第 2 行上放置一个断点,因此当您单步执行代码时会发生什么?代码是否与每个步骤一致?如果不是,则表明 Eclipse 与您的源代码具有不同版本的类。如果它们相同,我会尝试关闭较新的 eclipse 副本(我假设您已经尝试重新启动 eclipse),因为您可能发现了一个奇怪的错误(新版本可能已修复它或清理了一些陈旧数据)。抱歉,我不能提供更多帮助。