0

I have multiple interconnected beans in configuration and would like to test various operation after global state changed.

For example, I have execute() of some bean, after which many beans are changed.

Currently I put all check inside testExecute() method, but this method becomes huge and non-separated.

Is it possible to execute execute() before entire class run, i.e. just after context was initialized?

@BeforeClass methods should be static, while I need to have context already initialized and autowired. Is it possible?

UPDATE

Note, that running "before class" in Spring environment should also include control of when context initialization occurs. I.e. one may want to run some code before context initialized and after context initialized (but both cases before class).

UPDATE 2

Also, Spring & JUnit allows @DirtiesContext annotation, which means that context will be initialized again. In such cases, "before" methods should be called again and also in the appropriate order.

Dims
  • 47,675
  • 117
  • 331
  • 600
  • The `TestExecutionListeners` seem most appropriate. You have access to the `ApplicationContext` through the `TestContext`. – Sotirios Delimanolis Oct 06 '15 at 16:07
  • May I achieve more self-containment here? I already have a class for (java) config, also a class for test and now I need one more class for listener. So much classes! Would like to have one class to describe entire test! – Dims Oct 06 '15 at 19:14
  • I don't think there are any built-in solutions. I'd look into potentially subclassing `SpringJUnit4ClassRunner`. – Sotirios Delimanolis Oct 06 '15 at 19:16

0 Answers0