解决 redis 和 mysql 在单元测试会报错的问题

This commit is contained in:
YunaiV
2021-03-01 00:21:39 +08:00
parent 7bb2dd1167
commit 3320f42bd7
3 changed files with 23 additions and 11 deletions

View File

@ -1,7 +1,7 @@
package cn.iocoder.dashboard.config;
import io.reactivex.rxjava3.core.Scheduler;
import org.mockito.Mockito;
import org.quartz.impl.StdScheduler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
@ -11,8 +11,8 @@ import org.springframework.context.annotation.Lazy;
public class QuartzTestConfiguration {
@Bean
public Scheduler scheduler() {
return Mockito.mock(Scheduler.class);
public StdScheduler scheduler() {
return Mockito.mock(StdScheduler.class);
}
}

View File

@ -18,12 +18,24 @@ import java.io.IOException;
@AutoConfigureBefore({RedisAutoConfiguration.class, RedissonAutoConfiguration.class}) // 在 Redis 自动配置前,进行初始化
public class RedisTestConfiguration {
// /**
// * 创建模拟的 Redis Server 服务器
// */
// @Bean(initMethod = "start", destroyMethod = "stop")
// public RedisServer redisServer(RedisProperties properties) throws IOException {
// return new RedisServer(properties.getPort());
// }
/**
* 创建模拟的 Redis Server 服务器
*/
@Bean(initMethod = "start", destroyMethod = "stop")
@Bean(destroyMethod = "stop")
public RedisServer redisServer(RedisProperties properties) throws IOException {
return new RedisServer(properties.getPort());
RedisServer redisServer = new RedisServer(properties.getPort());
try {
redisServer.start();
} catch (Exception ignore) {}
return redisServer;
}
}