Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2204

@TestConfiguration for Embedded Redis, same Redis Server for all Test classes

$
0
0

I use a Embedded Redis for integration testing. I set up my tests with Redis according to following article: https://www.baeldung.com/spring-embedded-redis.

The problem is, if I want to use the @TestConfiguration with several test classes, I get errors because @PreDestroy is not called. The Embedded Redis is created new each time and is not shared between the test classes. It is therefore tried every time to create a new Redis Sserver on the same port, which leads to the following error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testRedisConfiguration': Invocation of init method failed; nested exception is java.lang.RuntimeException: Can't start redis server. Check logs for details.

When I add the @DirtiesContext to all test classes I get following error:

java.lang.IllegalStateException: org.springframework.web.context.support.GenericWebApplicationContext@255e5e2e has been closed already

Is there a way to use the same Embedded Redis for all my test classes?


Viewing all articles
Browse latest Browse all 2204

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>