简体   繁体   中英

How to debug methods called by JUnit in Eclipse?

If I write a test class such as:

public class TryOut {

    public int doStuff()
    {
        System.out.println("Hello");
        int five = 5;
        return five * 2;
    }

    public static void main(String[] args)
    {
        TryOut myTryOut = new TryOut();
        myTryOut.doStuff();
    }
}

and use JUnit to test it

import static org.junit.Assert.*;

import org.junit.Test;

public class TryOutTest {

    @Test
    public void test() {

        TryOut myTryOut = new TryOut();
        int answer = myTryOut.doStuff();
        assertEquals(10, answer);
    }

}

What I want is to step through the code when JUnit is running. Is this possible? If I set a breakpoint on the method that gets called - doStuff() and then right click on the TryOutTest class, then Debug As, JUnit test menu options, (to run the code) the breakpoint never stops the code, and the test completes.

Make sure that your breakpoint is not skipped (in case you see a backslash on the breakpoint, it is skipped). In case it is skipped, press Ctrl+Alt+B to enable it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM