Great post on junit method order execution
[Note this additional post on this topic]
With the addition of the ClassRule annotation in JUnit 4.9, I thought I’d come back and revisit JUnit test order execution.
@ClassRule fills a gap in the JUnit API, by providing class level rules like @BeforeClass and @AfterClass provide class-wide set up and tear down.
This article explains how to control code execution of unit tests and where @ClassRule fits in.
The terminology I use:
- A test implements @Test
- A test case in a class with @Test methods
Ordering test methods
The simplest test case you can write in JUnit is to annotate methods with @Test:
In OrderTest1, the execution order is:
Managing test fixtures
If you need to initialize the same data for each test, you put that data in instance variables and initialize them in a @Before setUp method. The setUp method is called before each @Test method.
View original post 598 more words