spring整合junit进行测试


以下只是一个模板,大家记得改变配置文件

package cn.itcast.crm.dao;

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 cn.itcast.crm.entity.Customer;


@ContextConfiguration(locations= {"classpath:applicationContext_dao.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
public class CustomerDaoImplTest {

	/*
	 * @Test
	 * public void test() { ApplicationContext ac=new
	 * ClassPathXmlApplicationContext("classpath:applicationContext_dao.xml");
	 * CustomerDao customerDao = (CustomerDao) ac.getBean("customerDao"); Customer
	 * customer = customerDao.findCustomerById(23L); System.out.println(customer); }
	 */
	@Autowired
	private CustomerDao customerDao;
	
	@Test	
	public void test() {
		Customer customer = customerDao.findCustomerById(23L);
		System.out.println(customer);
	}
	
	
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM