spring整合junit进行测试
Posted houchen
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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); } }
以上是关于spring整合junit进行测试的主要内容,如果未能解决你的问题,请参考以下文章