Prevent connection to Redis server in unit tests
<p>I am building an app with <code>spring-boot</code>. In order to avoid sticky-session related problems, I put in place a redis session store by adding those lines in <code>pom.xml</code> : </p>

<pre><code>&lt;dependency&gt;
  &lt;groupId&gt;org.springframework.session&lt;/groupId&gt;
  &lt;artifactId&gt;spring-session&lt;/artifactId&gt;
  &lt;version&gt;1.2.0.RELEASE&lt;/version&gt;
&lt;/dependency&gt;

&lt;dependency&gt;
  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  &lt;artifactId&gt;spring-boot-starter-redis&lt;/artifactId&gt;
&lt;/dependency&gt;
</code></pre>

<p>and those lines in application.properties : </p>

<pre><code>spring.redis.host=localhost
spring.redis.password=secret
spring.redis.port=6379
</code></pre>

<p>It worked like a charm. I was surprised that it worked even if I did not use the annotation <code>@EnableRedisHttpSession</code>. At the beginning, I found it nice.</p>

<p><strong>Problem</strong> : I have a Spring configuration for the real application and also a Spring configuration dedicated to unit tests. The Redis connection is useless in the unit test environment and make the test fail if I do not install a Redis server in the test environment.</p>

<p>I could eventually install a Mock Redis as a maven dependency but it would be cleaner if I found a way to disable this useless connection.</p>

<p>Any idea?</p>