测试方法中调用service与dao

1.类前加注释

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
     "classpath:mapper/bookmapper.xml"})

2.添加依赖

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.11</version>
    <scope>test</scope>
</dependency>
 
<!--spring-test-->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <version>4.1.0.RELEASE</version>
    <scope>test</scope>
</dependency>

3.进行测试

@Autowired
private SampleDao sampleDao;
@Test
public void testGetActivityId(){
     
    sampleDao.getActivityId();
}

你可能感兴趣的:(测试方法中调用service与dao)