Pregunta

I have a test case where I have an @Autowired Foo foo which I need to have injected just once, so all the test methods could re-use the same data foo has. What is currently happening is that upon every @Test method's invocation, the foo bean is cleanly re-loaded by Spring.

Is is possible to load this bean just once for the whole test class and how is it done?

¿Fue útil?

Solución

This behavior is probably environment specific since they differ in the loading of the Spring context. For example, Eclipse does not automatically reload the context between tests but Maven does.

I would suggest that you write a @Before method that copies the @Autowired reference into another field and have your tests use that field.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top