package com.xxx.test; import java.util.HashMap; import java.util.Map; 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.AbstractJUnit4SpringContextTests; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.xxx.XXXService; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "file:WebContent/WEB-INF/applicationContext.xml" }) public class XXXServiceTest extends AbstractJUnit4SpringContextTests { @Autowired XXXService xXXService; @Test public void search() { Map map = new HashMap(); map.put("id", 1); xXXService.xxxx(xxx ...); } }
主要注意locations 的写法,非spring配置文件不要加入
可参考
http://www.360doc.com/content/12/1014/00/7471983_241330790.shtml#