1. 程式人生 > >ssm單元測試類,springmvc,mybatis單元測試

ssm單元測試類,springmvc,mybatis單元測試

複製貼上直接用

import org.apache.ibatis.logging.Log; 
import org.apache.ibatis.logging.LogFactory; 
import java.util.Iterator;
import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.test.redis.dao.UserDao;
import com.test.redis.model.User;
@RunWith(SpringJUnit4ClassRunner.class) // 表示繼承了SpringJUnit4ClassRunner類 
@ContextConfiguration(locations = { "classpath:applicationContext.xml"}) //載入spring容器
//@ContextConfiguration(locations = { "classpath:spring-mybatis.xml"})  也可以這樣載入

public class junitDao {
	 private Log log = LogFactory.getLog(junitDao.class);
	 @Autowired
     private UserDao userDao;   //資料層介面
	 
 //@Transactional 事務處理  	 
	 @Test
	 public void test(){
		//呼叫資料介面測試
		 List<User> users = userDao.user();
		    Iterator<User> it = users.iterator();
		   while (it.hasNext()) {
		     System.err.println(it.next());
		}
	 }

}