Search code examples
javajunitjmock

Junit Jmock testing: multiple @Before for tests


I am not sure if it is possible to do, but I need to call different @Before methods depending on Tests. Is it possible, to make some resolver for it?

@Before
performBeforeOne();

@Before
performBeforeTwo();

@Test
callBeforeOneAndExecuteTestOne();

@Test
callBeforeTwoAndExecuteTestTwo();

Or should I just create several methods and call them manually from each test?


Solution

  • No, you can only have one method with each lifecycle annotation. Create a composite method that calls the others if they're too large to combine.