Need an example of using Junit in Intellij Idea

Maybe it's just me, but I can't understand the documentation regarding the integration of Junit tests in Intellij Idea. I am looking for a simple example of a tutorial, for example: Here is a method that calculates 2 + 2, and here is a test class that tests it as 4. This is the checkbox that you select to complete it. If you already have such a thing online or inside Intellij Idea Help, contact her. I am using Idea 7.0.4 and would like to use JUnit 3.8 or 4. *. TIA.

+7
intellij-idea junit
source share
1 answer

Here is a small example 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 appear at the top of the screen as a โ€œconfigurationโ€. You can then either click the green triangle to restart the test, or use the debug triangle to start in debug mode with breakpoints enabled.

+11
source share

All Articles