Spring Boot with datasource when testing
<p>I am using Spring Boot application and the auto cofiguration is enabled. The main Application file is marked as <code>@EnableAutoConfiguration</code>. The datasource is lookedup from JNDI is configured using java config and the class which create the datasource is marked as <code>@Configuration</code>.</p>

<p>I have a test class as below.</p>

<pre><code>@RunWith( SpringJUnit4ClassRunner.class )
@WebAppConfiguration
@ContextConfiguration( classes = Application.class )
public class TestSomeBusiness {}
</code></pre>

<p>The issue is when I run the test case, the datasource jndi lookup happens, which fails because the test case is not running inside a server environment. As far as I know the classes in classpath marked with <code>@Configuration</code> are executed and that the reason the datasource lookup is being called.</p>

<p>The work around for now I have found is instead of JNDI lookup create the datasource using <code>DriverManagerDataSource</code>, so that even if its not a server environment the datasource lookup won't fail.</p>

<p>My questions are:</p>

<p>1) How do we generally deal with datasource (when looking up from JNDI) in 
spring boot application for testing ?</p>

<p>2) Is there a way to exclude the datasource configuration class from being called when executing test case ?</p>

<p>3) Should I create an embedded server so that the JNDI lookup can be done when executing test case ?</p>