0

I am playing with writing integration tests for our project. This is the first time I am writing tests so please pardon me if this is a simple question.

I have different modules like core, site, admin etc.,

I want to keep our unit tests separate from our integration tests. So in the core of the project, I created a folder src/it/java and a package in it - com.test.integration. This package has the test that I am trying to run.

The test application context and required test properties files are in src/it/java directly. I added src/it/java to my build path. In my application context I have the following

<bean id="dataSource" 
      class="org.apache.commons.dbcp.BasicDataSource"
      destroy-method="close">
    <property name="url" value="jdbc:mysql://${mysql.host}/${mysql.db_blc}?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=UTF8"/>
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="username" value="${mysql.user}" />
    <property name="password" value="${mysql.pass}" /> 
    <property name="testWhileIdle" value="true"/>
    <property name="testOnBorrow" value="true"/>
    <property name="testOnReturn" value="false"/>
    <property name="validationQuery" value="SELECT 1"/>
</bean>

<bean id="jdbcTemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
    <constructor-arg ref="dataSource" /> 
</bean>

Now in my sample test

@RunWith(BlockJUnit4ClassRunner.class)
@ContextConfiguration("/applicationContext-test.xml")
public class SampleTest {
    @Resource(name="jdbcTemplate")
private NamedParameterJdbcTemplate jdbcTemplate;
}

The jdbcTemplate bean is null and I can't seem to figure out why.

Any input is appreciated. We are using Spring 3.0.5 and JUnit4

Thanks Mehul

4

1 回答 1

0
  1. 尝试使用SpringJunit4ClassRunner
  2. 我建议将上下文配置更改为此 @ContextConfiguration("classpath:/applicationContext-test.xml")
于 2014-01-08T02:29:29.157 回答