JUnit 4 @Before and @BeforeClass differences

Hi,

In JUnit 4 what are @Before and @BeforeClass differences. when we use which one. What are other important annotations we have there. please advise
LVL 7
gudii9Asked:
Who is Participating?
 
dpearsonCommented:
@Before runs before each test.
@BeforeClass runs once before any of the tests.

So you can use @BeforeClass to setup mock data that you will use in all of the tests (e.g. if you're testing a class of orders, this might create a list of orders to work with).

And @Before you can use for mock data that needs to be recreated over and over (e.g. you might create a single order object which you will modify in the test and so you want to always start with a blank order before each test runs).

Make sense?

Doug
0
 
gudii9Author Commented:
Let me think. Amy good sample ecamples, links to practice?
0
All Courses

From novice to tech pro — start learning today.