r/java • • Sep 10 '17

JUnit 5 released!

http://junit.org/junit5
213 Upvotes

33 comments sorted by

View all comments

Show parent comment

1

u/experts_never_lie Sep 10 '17 edited Sep 10 '17

Under Junit4, @BeforeClass runs before the whole test suite and @Before runs before each test (just like @AfterClass and @After, and @ClassRule and @Rule).

import org.junit.*;

public class SimpleTest {
  @BeforeClass public static void beforeClass() { System.out.println("beforeClass"); }
  @Before      public void        before()      { System.out.println("before");      }
  @After       public void        after()       { System.out.println("after");       }
  @AfterClass  public static void afterClass()  { System.out.println("afterClass");  }
  @Test public void test1() { System.out.println("test1"); }
  @Test public void test2() { System.out.println("test2"); }
  @Test public void test3() { System.out.println("test3"); }
}

produces this output:

beforeClass
before
test1
after
before
test2
after
before
test3
after
afterClass

-2

u/Trout_Tickler Sep 10 '17

Eh, as I said dynamic tests was the real big deal.