Tuesday, February 8, 2011

Integration testing a mvn java spring jdbc app

Basically all you really need is to make sure that the spring resources are on the build path when you're tests run.

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/java</directory>
<includes>
<include>**</include>
</includes>
<excludes>
<!-- <exclude>**/*.java</exclude> -->
</excludes>
</testResource>
<testResource>
<directory>../consultantreg-config/references/default</directory>
</testResource>
</testResources>
</build>

Then, in your actual junit test, make sure you have it properly annotated:
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"/applicationContext-common.xml"})
public class IntegrationTestsSomeJdbcDao {