mybatis-plus icon indicating copy to clipboard operation
mybatis-plus copied to clipboard

想在没有启动类的模块中写单元测试应该如何处理呢

Open ideaviewes opened this issue 7 months ago • 1 comments

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

3.5.4.1

该问题是如何引起的?(确定最新版也有问题再提!!!)

执行单元测试的时候

重现步骤(如果有就写完整)

单元测试的代码如下

@Slf4j
@MybatisPlusTest
@ContextConfiguration(classes = {
        DataSource.class,
        RbacRoleResourceServiceImpl.class,
        RbacResourceServiceImpl.class
})
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@MapperScan(basePackageClasses = {RbacRoleResourceMapper.class, RbacResourceMapper.class})
class RbacRoleResourceServiceImplTest {
    @Resource
    public RbacRoleResourceService rbacRoleResourceService;
    @Resource
    public RbacResourceService rbacResourceService;

    @Test
    void assignResourcesToRole() {
        List<Long> resourceIds = rbacResourceService.lambdaQuery().select(RbacResource::getId)
                .list().stream().mapToLong(RbacResource::getId)
                .boxed().toList();
        rbacRoleResourceService.assignResourcesToRole(1L,resourceIds);
    }
}

报错信息

单元测试所在的模块,没有启动类,我把需要的bean都注入了一下,可以执行了,但是控制台警告: 23:34:37 WARN 9404 --- [ main] o.m.s.mapper.ClassPathMapperScanner : Skipping MapperFactoryBean with name 'rbacResourceMapper' and 'com.icodeview.dream.model.mapper.RbacResourceMapper' mapperInterface. Bean already defined with the same name! 23:34:37 WARN 9404 --- [ main] o.m.s.mapper.ClassPathMapperScanner : Skipping MapperFactoryBean with name 'rbacRoleMapper' and 'com.icodeview.dream.model.mapper.RbacRoleMapper' mapperInterface. Bean already defined with the same name! 23:34:37 WARN 9404 --- [ main] o.m.s.mapper.ClassPathMapperScanner : Skipping MapperFactoryBean with name 'rbacRoleResourceMapper' and 'com.icodeview.dream.model.mapper.RbacRoleResourceMapper' mapperInterface. Bean already defined with the same name! 23:34:37 WARN 9404 --- [ main] o.m.s.mapper.ClassPathMapperScanner : Skipping MapperFactoryBean with name 'rbacUserMapper' and 'com.icodeview.dream.model.mapper.RbacUserMapper' mapperInterface. Bean already defined with the same name! 23:34:37 WARN 9404 --- [ main] o.m.s.mapper.ClassPathMapperScanner : Skipping MapperFactoryBean with name 'rbacUserRoleMapper' and 'com.icodeview.dream.model.mapper.RbacUserRoleMapper' mapperInterface. Bean already defined with the same name! 这个模块除了单元测试这个类,没有@MapperScan,如果我去掉这行的话,@MapperScan(basePackageClasses = {RbacRoleResourceMapper.class, RbacResourceMapper.class}),就直接报错mapper找不到。 所以我有点怀疑是@MybatisPlusTest注解有问题?

ideaviewes avatar Dec 01 '23 15:12 ideaviewes