2 wxx151556 wxx151556 于 2017.08.29 09:10 提问

SpringBoot+MyBatis框架的项目,如何进行集成测试?

**@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(
classes = Application.class,
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT
)
@DirtiesContext
public class dataOpTest {

private TBookController tBookController = new TBookController();
public TBookMapper tBookMapper;

@Test
public void testIfExistByName(){
    String bk_name = "c++";
    //int existCount = tBookController.ifExist(bk_name);
    int result = tBookMapper.existByNameAndState(bk_name);
    Assert.assertEquals(result, 1);
}

}**
以上代码,会认为tBookController是空指针,它本身是一个接口,sql实现都在xml文件里面,但是集成测试的时候怎么做?

2个回答

wo_01220452
wo_01220452   2017.08.29 09:19
Small_Mouse0
Small_Mouse0   Ds   Rxr 2017.08.29 09:59

tBookController是空指针???不是吧,,,你后面都new了,,,

tBookMapper的空指针吧

加个注解试试”@Autowired “,,把new去了
两个都加上试试

Csdn user default icon
上传中...
上传图片
插入图片