Implementing JUnit with Spring

We Need junit- 4.x jar and spring-test-2.5.6.jar

 * To change this template, choose Tools | Templates
 * and open the template in the editor.
package com.taher.test.controller;

import com.taher.test.dao.StudentMasterDao;
import com.taher.test.model.StudentMaster;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.junit.runner.RunWith;
import junit.framework.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

 * @author taher
@ContextConfiguration(locations = {"classpath:/ApplicationContext.xml"})
public class StudentControllerTest {

    private StudentMasterDao studentMasterDao;

    public StudentMasterDao getStudentMasterDao() {
        return studentMasterDao;

    public void setStudentMasterDao(StudentMasterDao studentMasterDao) {
        this.studentMasterDao = studentMasterDao;

    public StudentControllerTest() {

    public void testSetStudentDetailDao() {
        System.out.println("Obj : " + studentMasterDao);
        for (StudentMaster object : studentMasterDao.getAllStudentMaster()) {
            System.out.println(object.getStudentFirstname() + " : " + object.getStudentLastname());
        String one = "abc";
        String two = "abc";
        Assert.assertEquals(one, two);
        // TODO review the generated test code and remove the default call to fail.
        //fail("The test case is a prototype.");
This entry was posted in Hibernate, JUnit, Spring. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s