views:

2370

answers:

1

Maybe it's just me, but I cannot understand the documentation regarding Junit test integration in Intellij Idea. What I am looking for is a simple tutorial example, such as: Here is a method calculating 2+2, and here is a test class testing it to be 4. This is the checkbox you set to make it go. If there is already such a thing on the web or inside the Intellij Idea help, please refer me to it. I use Idea 7.0.4 and would like to use JUnit 3.8 or 4.*. TIA.

+3  A: 

Here is a small sample of how I use intellij with junit

public class MathTest {  // Press Ctrl-Shift-F10 here to run all tests in class
    @Test
    public void twoPlusTwo() { // Press Ctrl-Shift-F10 here to run only twoPlusTwo test
        assertThat( 2+2, is( 4 ) );
    }

    @Test
    public void twoPlusThree() { // Press Ctrl-Shift-F10 here to run only twoPlusThree test
        assertThat( 2+3, is( 5 ) );
    }
}

Once you run the test once, it will show up at the top of the screen as a run "configuration". Then you can either hit the green triangle to rerun the test, or use the debug triangle to run in debug mode with breakpoints enabled.

Alex B