码迷,mamicode.com
首页 > 编程语言 > 详细

spring整合junit进行测试

时间:2019-04-23 09:48:01      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:autowire   tom   一个   runner   import   customer   package   framework   text   

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

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);
	}
	
	
}

 

spring整合junit进行测试

标签:autowire   tom   一个   runner   import   customer   package   framework   text   

原文地址:https://www.cnblogs.com/houchen/p/10754376.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!