我可以使用 Eclipse IDE 强制 Junit 调试器通过自定义测试用例方法开始调试执行吗?

Can I force Junit debugger to start debugging execution by a custom test case method using Eclipse IDE?

我有一个测试 Class 包含 3 个测试方法,如下例

public class SampleTest {
    @Test
    public void testAdd() {
        // logic of testing ADD
    }
    @Test
    public void testUpdate() {
        // logic of testing UPDATE
    }
    @Test
    public void testDelete() {
        // logic of testing Delete
    }
}

我只想调试第二种方法testUpdate()
没有开始执行任何其他测试用例 testAdd()/testDelete()

当我把breakpoints放在所有测试方法中时
我发现
未授予执行顺序,在某些情况下 testAdd()/testDelete() 方法在 testUpdate()
之前 运行 秒 这些情况浪费时间,因为我只需要调试 method2 = testUpdate(),
那么为什么我应该等待 method1 或 method3 被执行,但是它们 运行 很快

总结
我可以使用 Eclipse IDE 强制 Junit 调试器通过自定义测试用例方法开始执行吗?

您可以使用测试执行顺序:

https://github.com/junit-team/junit4/wiki/test-execution-order

其他方式:

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@FixMethodOrder(MethodSorters.JVM)
@FixMethodOrder(MethodSorters.DEFAULT)

例如,通过选择使用 NAME_ASCENDING,您应该更改第二个测试名称,使其按字母顺序排在其他测试之前

您是否尝试过select使用该方法并单击调试?或者您是否尝试过执行整个测试然后 select 您的方法右键单击并调试?

首选方式:任何现代IDE都能够运行并调试特定测试。请参阅 IDE.

的手册

肮脏的方式:忽略其余测试用例,除了一个:

public class SampleTest {
    @Test
    @Ignore
    public void testAdd() {
        // logic of testing ADD
    }

    @Test
    public void testUpdate() {
        // logic of testing UPDATE
    }

    @Test
    @Ignore
    public void testDelete() {
        // logic of testing Delete
    }
}

非常感谢@Dmytro 的评论。
解决方案将是

  1. Package ExplorerOutline视图中
  2. 展开包含测试方法的测试Class。
  3. 右键单击您想要的所需方法Debug
  4. Select Debug As => JUnit Test