前提是引入两个包:org.springframework.test-3.1.3.RELEASE和JUnit4.
package com.qk.test; import javax.annotation.Resource; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.qk.dao.UserDao; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({"file:D:/javaworkspace/QK-T10/build/classes/config/spring/application-context.xml"}) public class TestVirtualTeamDao { @Resource private UserDao userDao; @Test public void testGet() { System.out.println(userDao.get(10)); } }
@ContextConfiguration这里的路径是spring配置文件的路径