Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prepare state for several JUnit tests only once

Tags:

junit

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 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?

like image 559
Aivar Avatar asked Dec 13 '22 16:12

Aivar


1 Answers

Use the annotation @BeforeClass to annotate the method which will be run once before all test methods.

like image 111
Boris Pavlović Avatar answered Feb 11 '23 13:02

Boris Pavlović