标签: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); } }
标签:autowire tom 一个 runner import customer package framework text
原文地址:https://www.cnblogs.com/houchen/p/10754376.html