版权声明:不卑不亢,不骄不躁---好男人就是我,我就是曾哥. https://blog.csdn.net/weixin_42884584/article/details/82432978
除了要junit的包4.0以上的,还要spring-test的包
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.2.4.RELEASE</version>
<scope>test</scope>
</dependency>
然后在测试类上使用RunWith和ContextConfiguration注解,还有方法上要加Test注解。
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:spring/applicationContext-*.xml"})
public class TestSearchItemMapper {
@Autowired
private SearchItemMapper searchItemMapper;
@Test
public void testGetItemList() {
List<SearchItem> searchItemList = searchItemMapper.getItemList();
for (SearchItem s : searchItemList) {
System.out.println(s);
}
}
}