0

I have a Test Class containing 3 test methods like below example

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
    }
}

I want to debug ONLY the second method testUpdate()
WITHOUT starting execution by any of other test cases testAdd()/testDelete()

When I put breakpoints in all test methods
I found that
Order of Execution not granted, and in some cases testAdd()/testDelete() methods runs before testUpdate()
Those cases waste a time because, I need to debug ONLY method2 = testUpdate(),
So why I should wait method1 or method3 to be executed however they are run quickly

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

Ahmed Nabil
  • 17,392
  • 11
  • 61
  • 88

4 Answers4

1

You can use test execution order :

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

other means :

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

by choosing for example to use NAME_ASCENDING you should change the second test name to make it alphabetically came before the other tests

Lho Ben
  • 2,053
  • 18
  • 35
1

have you tried selecting the method and click debug? or have you tried executing whole tests and later select your method right click and debugg?

Khalil M
  • 1,788
  • 2
  • 22
  • 36
1

Preferred way: any modern IDE has an ability to run and debug a specific test. Refer a manual of your IDE.

Dirty way: ignore the rest test cases except one:

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 Maslenko
  • 2,247
  • 9
  • 16
0

Thanks a lot to @Dmytro comment.
The solution will be

  1. In the Package Explorer or Outline view
  2. Unfold the Test Class which contain test methods.
  3. Right click on the required method you want to Debug
  4. Select Debug As => JUnit Test
Ahmed Nabil
  • 17,392
  • 11
  • 61
  • 88
  • Yes this is in some way what I answered you – Khalil M Jan 20 '19 at 21:54
  • @KhalilM No dear, its a different, you mentioned that `selecting the method and click debug` but the right way to `select method In the Package Explorer or Outline view` ... anyway Thank you! – Ahmed Nabil Jan 20 '19 at 21:59