当前位置:网站首页>单元测试中遇到的怪事
单元测试中遇到的怪事
2022-06-09 08:45: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("配置1");
vo.setValue("111");
vo.setVisible(true);
if (configService.createConfig(vo)>0){
ConfigDO v= configService.getConfigByKey("key1");
System.out.println(v);
}
}
}
针对某个单元进行测试,很正常的一段测试代码,如上。加载的时候就出错,貌似数据源加载失败
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="")}
而事实上数据源配置都是正确的。
后面引用了这个MockBean实例就OK了,而这个实例只是个mq通知组件,跟数据源无关。不是测试仔感觉一脸懵逼。
@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("配置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();
}
}
边栏推荐
- Use Flashback Database and restore point
- RMAN backup concept_ Consistent and inconsistent RMAN backups
- If and ifnull in MySQL
- The integrated monitoring system of ankerui distribution room realizes the online monitoring of the environment in the distribution room and ensures the safe operation of the equipment in the distribu
- 2022年5月29日16:05:09
- RMAN backup concept_ Online backup and backup mode
- 48-OIDC OP配置信息端点
- About Matrix Decompositions
- Configuring the environment for RMAN backups
- Openinfra summit 2022 𞓜 Android cloud users stand out and are shortlisted for the super user Award
猜你喜欢

RMAN备份概念_关于备份保留策略(RETENTION POLICY)

Compilation_ Basic concepts

How to solve the problem of mouseup event invalidation
![[untitled]](/img/f9/f07f85bbf9881b5d30eb11ee1790b3.png)
[untitled]

常用windwos api

Remote prepayment management system helps property management solve the problem of difficult charging and statistics

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

Nodejs uses net module to create TCP server and client

Compilation_ Common instructions

10种提问型爆文标题句式 直接套用
随机推荐
85.(leaflet之家)leaflet军事标绘-直线箭头绘制
Oracle locally managed tablespaces
10种提问型爆文标题句式 直接套用
Configuring the environment for RMAN backups_ Configure advanced backup options
Sql: reformat department table (row to column problem: group by + aggregate function)
RMAN backup concept_ Online backup and backup mode
The energy efficiency management platform of the microgrid of the company promotes the upgrading of the power grid to the energy Internet
Sql: median employee salary
小米官网移动端布局
Mode de programmation 3D: mode d'isolement dépendant
框架初入门:更新表达式无效 ,必须至少更新一列
清洗数据---2022/06/08
RMAN backup concept_ Consistent and inconsistent RMAN backups
RMAN backup concept_ About RMAN incremental backup
English grammar_ Adverbs of Time
RMAN备份概念_关于备份保留策略(RETENTION POLICY)
Configuring the environment for RMAN backups_ Configure backup optimization
10 useful flutter widgets
Summary of string inversion methods
49-OAuth2授权码中PKCE的配置