???????????junit.jar;org.springframework.test-3.1.0.RELEASE.jar
????????Dao??????JUnitDaoBase

 

package test.test;
import javax.annotation.Resource;
import javax.sql.DataSource;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* <b>Summary: </b> TODO Junit ?????????????
* <b>Remarks: </b> TODO DAO?????????
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:/config/applicationContext.xml"})
public  class JUnitDaoBase extends AbstractTransactionalJUnit4SpringContextTests {
/**
* <b>Summary: </b> ??д???? setDataSource
*
* @param dataSource
* @see org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests#setDataSource(javax.sql.DataSource)
*/
@Override
@Resource(name = "myDataSource")
public void setDataSource(DataSource dataSource) {
// TODO Auto-generated method stub
super.setDataSource(dataSource);
}
}

????????dao ??????daoBaseTest??????

 

package test.java.dao;
import java.util.List;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import com.pinfang.dao.UserDao;
import com.pinfang.vo.User;
import test.test.JUnitDaoBase;
/**
* dao?????????
* @author fule
*
*/
public class UserDaoTest extends JUnitDaoBase {
@Autowired
private UserDao userDao;
@Test
public void testUserDao() {
User user = new User();
user.setPassword("123456");
user.setName("????");
user.setSex(1);
//System.out.println(userDao.findOnValidate(user).getMark());
List<User> list = userDao.getAll();
System.out.println(list);
//System.out.println(userDao.findOneByName("????s"));
//System.out.println(userDao.addUser(user));
}
}