spring boot maven多模块项目编写单元测试

pom中加依赖

           <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <version>${spring-boot.version}</version>
                <scope>test</scope>
            </dependency>

测试类的注解

IDEA工具中可以快捷生成测试类(光标放在指定类名上,Alt+Enter即可生成测试类)
测试类上注解只需要
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = TestRunner.class)
@SpringBootTest(classes=.class) = @SpringApplicationConfiguration(1.4.0之后不再使用)
在测试类中引入需要注入的Bean即可成功,再加上断言 单元测试编写成功

————–华丽丽的分界线————

But……我们的项目service的单元测试中mapper接口怎么也无法注入,报错信息如下:大概意思就是说我们的mapper接口注入失败blabla的。

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.pinganfu.dayu.service.LoginServiceTest': Unsatisfied dependency expressed through field 'userMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.pinganfu.dayu.dal.mapper.UserMapper' avai
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值