juniorbansal
juniorbansal

Reputation: 1271

springjunit4classrunner test case throwing null pointer

I am using JUNIT4 + Spring and wrote a test case. I wired in a JDBC Template and did manual set on it. But that turns out be null and the test is throwing null pointer exception when i use that injected variable. What's wrong here?

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:applicationContextTest.xml" })
@TransactionConfiguration(defaultRollback = true)
@Configurable
public class WriterTest {


    private JdbcTemplate utilityJdbcTemplate;

    public void setUtilityJdbcTemplate(JdbcTemplate utilityJdbcTemplate) {
        this.utilityJdbcTemplate = utilityJdbcTemplate;
    }



    @Test
    @Transactional
    @Rollback(true)
    public void testHappyPath() {
        Assert.assertNotNull(utilityJdbcTemplate);

    }
}

Here the test fails because utilityJdbcTemplate being null. why?

Upvotes: 0

Views: 936

Answers (1)

tolitius
tolitius

Reputation: 22549

"gotta autowire":

@Autowired
private JdbcTemplate utilityJdbcTemplate;

Upvotes: 2

Related Questions