How to prepare state for several JUnit tests only once
I need to test a program that first preprocesses some data and then computes several different results using this preprocessed data -- it makes sense to开发者_如何学JAVA write separate test for each computation.
Official JUnit policy seems to be that I should run preprocessing before each computation test. How can I set up my test so that I could run the preparation only once (it's quite slow) before running remaining tests?
Use the annotation @BeforeClass to annotate the method which will be run once before all test methods.
精彩评论