The reason you need it is because for many tests, you often need to initialize the state before each test so that the tests can make assumptions about the startup state in which they work.
Suppose your test class wraps, say, database access. After each test, you want to delete all the changes made by your tests in db - if you did not, each test is performed against a slightly modified database. In addition, any given test may see a different set of changes if some subsets of previous tests failed. For example, suppose test1 inserts, test2 checks that you are reading the size of the table exactly. Day 1, test1 fails, and 0 is correct. Day 2, test1 succeeds, and 1 correct?
BTW, junit also supports @BeforeClass if you want to perform global configuration, and configuration and disabling are optional.
Steve B. Sep 06 '10 at 2:36
source share