How to run global junit5 test setup depending on spring bean?

17 Views Asked by At

I need to do some setup before all my test run; that setup needs to use a spring bean. I already searched for this and I found the solution to autowire the bean in a statis test method.

@JvmStatic
@BeforeAll
loadPersona(@Autowired esClient: ElasticsearchClient, @Autowired objectMapper: ObjectMapper) { ... }

This worked fine, until a few days ago it stated failing with this error:

ParameterResolution Failed to resolve parameter [co.elastic.clients.elasticsearch.ElasticsearchClient esClient] in method [public static final void be.vdab.vewn.bemiddeldprofiel.AbstractBootifulIntegrationTest.loadPersona(co.elastic.clients.elasticsearch.ElasticsearchClient,com.fasterxml.jackson.databind.ObjectMapper)]

I suspect the application context is not fully loaded when it tries to execute the static method. But I'm not sure and I wonder how to avoid this issue.

0

There are 0 best solutions below