当前位置:网站首页>Strange things in unit testing
Strange things in unit testing
2022-06-09 08:57:00 【OK_ boom】
@Import(ConfigServiceImpl.class)
public class ConfigServiceTest extends BaseDbUnitTest {
@Resource
private ConfigServiceImpl configService;
@Test
public void testConfig(){
ConfigCreateReqVO vo=new ConfigCreateReqVO();
vo.setCategory("cust");
vo.setKey("key1");
vo.setName(" To configure 1");
vo.setValue("111");
vo.setVisible(true);
if (configService.createConfig(vo)>0){
ConfigDO v= configService.getConfigByKey("key1");
System.out.println(v);
}
}
}
Test a unit , A very normal section of test code , Above . Error when loading , It seems that the data source failed to load
Positive matches:
-----------------
DataSourceAutoConfiguration matched:
- @ConditionalOnClass found required classes 'javax.sql.DataSource', 'org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType' (OnClassCondition)
- @ConditionalOnMissingBean (types: io.r2dbc.spi.ConnectionFactory; SearchStrategy: all) did not find any beans (OnBeanCondition)
DataSourceAutoConfiguration.PooledDataSourceConfiguration matched:
- AnyNestedCondition 1 matched 1 did not; NestedCondition on DataSourceAutoConfiguration.PooledDataSourceCondition.PooledDataSourceAvailable PooledDataSource found supported DataSource; NestedCondition on DataSourceAutoConfiguration.PooledDataSourceCondition.ExplicitType @ConditionalOnProperty (spring.datasource.type) did not find property 'type' (DataSourceAutoConfiguration.PooledDataSourceCondition)
- @ConditionalOnMissingBean (types: javax.sql.DataSource,javax.sql.XADataSource; SearchStrategy: all) did not find any beans (OnBeanCondition)
DataSourceConfiguration.Hikari matched:
...
org.springf
ramework.beans.factory.BeanCreationException: Error creating bean with name 'com.freestyle.yudao.module.custom.script.service.script.ConfigServiceTest': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cn.iocoder.yudao.module.infra.service.config.ConfigServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'cn.iocoder.yudao.module.infra.mq.producer.config.ConfigProducer' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {
@javax.annotation.Resource(shareable=true, lookup="", name="", description="", authenticationType=CONTAINER, type=java.lang.Object.class, mappedName="")}
In fact, the data source configuration is correct .
This is quoted later MockBean The example is OK 了 , And this example is just mq Notification component , Independent of data source . It's not that the tester feels confused .
@Import(ConfigServiceImpl.class)
public class ConfigServiceTest extends BaseDbUnitTest {
@Resource
private ConfigServiceImpl configService;
@MockBean
private ConfigProducer configProducer;
@Test
public void testConfig(){
ConfigCreateReqVO vo=new ConfigCreateReqVO();
vo.setCategory("cust");
vo.setKey("key1");
vo.setName(" To configure 1");
vo.setValue("111");
vo.setVisible(true);
if (configService.createConfig(vo)>0){
ConfigDO v= configService.getConfigByKey("key1");
System.out.println(v);
}
verify(configProducer, times(1)).sendConfigRefreshMessage();
}
}
边栏推荐
猜你喜欢

Application of acrel bus intelligent lighting control system in hospital

测试不会被开发取代吗?

Open source EDA software yosys for integrated circuit design 1: tool installation

How to view websites or apps bound to mobile phones: what you must do before you log off your mobile phone number - change and bind all websites or apps bound to your old mobile phone number

Self made compiler learning 1: use of CB compiler

redhat7 破解(重置)root密码

ESP32学习笔记【WiFi网络篇】-01AP&STA

shellcode编写

Use of extensions and super

模拟面试策划书;校园模拟面试策划书;求职模拟面试大赛策划书;经管学院模拟求职大赛策划书;大学生模拟面试大赛策划书
随机推荐
配置Conda环境和Pytorch安装
Self made compiler learning 1: use of CB compiler
ESP32学习笔记【WiFi网络篇】-01AP&STA
SQL: 重新格式化部门表 (行转列问题:Group by + 聚合函数)
防火门监控系统对防火门状态进行24小时实时自动巡检
Self made compiler learning 3: introduction to flex and bison
常用windwos api
虚拟机安装及配置
安科瑞配电室综合监控系统实现配电室内环境的在线监测,保障配电室设备的安全运行
FreeRtos任务通知复习
web知识点123
如何使用阿里云 CDN 对部署在函数计算上的静态网站进行缓存
SQL: 销售分析III
MySQL在存储过程中使用while批量插入数据(批量提交和单个提交的性能差异)
剖析虚幻渲染体系(15)- XR专题
Modify PE program entry point
The fire door monitoring system carries out 24-hour real-time automatic inspection on the status of the fire door
【Redis学习11】分布式缓存之数据持久化,主从集群
腾讯云宝塔搭建网站注意事项
The application of the comprehensive energy efficiency management system of ankery in the data center