I set up a class with a couple of tests and rather than using @Before I would like to have a setup method that executes only once before all tests. Is that possible with Junit 4.8?
I set up a class with a couple of tests and rather than using
Share
Although I agree with @assylias that using
@BeforeClassis a classic solution it is not always convenient. The method annotated with@BeforeClassmust be static. It is very inconvenient for some tests that need instance of test case. For example Spring based tests that use@Autowiredto work with services defined in spring context.In this case I personally use regular
setUp()method annotated with@Beforeannotation and manage my customstatic(!)booleanflag: