当前使用版本(必须填写清楚,否则不予处理)

3.0.7.1

该问题是

如何进行分层写测试用例; 比如测试mapper层问题

@RunWith(SpringRunner.class) @MybatisTest @Import(MybatisConfig.class) ... @Test ...

再比如只测试service层

@ContextConfiguration(classes = .....ServiceImpl.class)

会报告错误没有baseMapper , 无法注入mapper... Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'xxxServiceImpl': Unsatisfied dependency expressed through field 'baseMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.keruyun.crm.config.dao.xxxMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations:{@org.springframework.beans.factory.annotation.Autowired(required=true)}

貌似必须启动整个工程做测试用例,给个支持方向?

Comment From: miemieYaho

自己去研究

Comment From: lehug

官方应该给个demo呀,我看sample里面也没找到demo

Comment From: lehug

@MybatisPlusTest(includeFilters = @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = {Service.class})) 因为mp的serviceImpl 通过@Autowired注入了,想要getBaseMapper()不是空,就必须要把service,mapper一起注入了。

不过这样有个缺点,service,mapper的层次概念模糊了,不过mp带的lambda之类的,也确实模糊了service,mapper的概念了吧