Commit 3320f42bd7cfb0c8c1c7e63bb5aab181c2a4e169
1 parent
7bb2dd11
解决 redis 和 mysql 在单元测试会报错的问题
Showing
3 changed files
with
23 additions
and
11 deletions
src/test/java/cn/iocoder/dashboard/config/QuartzTestConfiguration.java
| 1 | 1 | package cn.iocoder.dashboard.config; |
| 2 | 2 | |
| 3 | -import io.reactivex.rxjava3.core.Scheduler; | |
| 4 | 3 | import org.mockito.Mockito; |
| 4 | +import org.quartz.impl.StdScheduler; | |
| 5 | 5 | import org.springframework.context.annotation.Bean; |
| 6 | 6 | import org.springframework.context.annotation.Configuration; |
| 7 | 7 | import org.springframework.context.annotation.Lazy; |
| ... | ... | @@ -11,8 +11,8 @@ import org.springframework.context.annotation.Lazy; |
| 11 | 11 | public class QuartzTestConfiguration { |
| 12 | 12 | |
| 13 | 13 | @Bean |
| 14 | - public Scheduler scheduler() { | |
| 15 | - return Mockito.mock(Scheduler.class); | |
| 14 | + public StdScheduler scheduler() { | |
| 15 | + return Mockito.mock(StdScheduler.class); | |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | } | ... | ... |
src/test/java/cn/iocoder/dashboard/config/RedisTestConfiguration.java
| ... | ... | @@ -18,12 +18,24 @@ import java.io.IOException; |
| 18 | 18 | @AutoConfigureBefore({RedisAutoConfiguration.class, RedissonAutoConfiguration.class}) // 在 Redis 自动配置前,进行初始化 |
| 19 | 19 | public class RedisTestConfiguration { |
| 20 | 20 | |
| 21 | +// /** | |
| 22 | +// * 创建模拟的 Redis Server 服务器 | |
| 23 | +// */ | |
| 24 | +// @Bean(initMethod = "start", destroyMethod = "stop") | |
| 25 | +// public RedisServer redisServer(RedisProperties properties) throws IOException { | |
| 26 | +// return new RedisServer(properties.getPort()); | |
| 27 | +// } | |
| 28 | + | |
| 21 | 29 | /** |
| 22 | 30 | * 创建模拟的 Redis Server 服务器 |
| 23 | 31 | */ |
| 24 | - @Bean(initMethod = "start", destroyMethod = "stop") | |
| 32 | + @Bean(destroyMethod = "stop") | |
| 25 | 33 | public RedisServer redisServer(RedisProperties properties) throws IOException { |
| 26 | - return new RedisServer(properties.getPort()); | |
| 34 | + RedisServer redisServer = new RedisServer(properties.getPort()); | |
| 35 | + try { | |
| 36 | + redisServer.start(); | |
| 37 | + } catch (Exception ignore) {} | |
| 38 | + return redisServer; | |
| 27 | 39 | } |
| 28 | 40 | |
| 29 | 41 | } | ... | ... |
src/test/resources/sql/create_tables.sql
| 1 | 1 | -- inf 开头的 DB |
| 2 | 2 | |
| 3 | -CREATE TABLE "inf_config" ( | |
| 3 | +CREATE TABLE IF NOT EXISTS "inf_config" ( | |
| 4 | 4 | "id" int NOT NULL GENERATED BY DEFAULT AS IDENTITY, |
| 5 | 5 | "group" varchar(50) NOT NULL, |
| 6 | 6 | "type" tinyint NOT NULL, |
| ... | ... | @@ -19,7 +19,7 @@ CREATE TABLE "inf_config" ( |
| 19 | 19 | |
| 20 | 20 | -- sys 开头的 DB |
| 21 | 21 | |
| 22 | -CREATE TABLE "sys_dept" ( | |
| 22 | +CREATE TABLE IF NOT EXISTS "sys_dept" ( | |
| 23 | 23 | "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, |
| 24 | 24 | "name" varchar(30) NOT NULL DEFAULT '', |
| 25 | 25 | "parent_id" bigint NOT NULL DEFAULT '0', |
| ... | ... | @@ -36,7 +36,7 @@ CREATE TABLE "sys_dept" ( |
| 36 | 36 | PRIMARY KEY ("id") |
| 37 | 37 | ) COMMENT '部门表'; |
| 38 | 38 | |
| 39 | -CREATE TABLE "sys_dict_data" ( | |
| 39 | +CREATE TABLE IF NOT EXISTS "sys_dict_data" ( | |
| 40 | 40 | "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, |
| 41 | 41 | "sort" int NOT NULL DEFAULT '0', |
| 42 | 42 | "label" varchar(100) NOT NULL DEFAULT '', |
| ... | ... | @@ -52,7 +52,7 @@ CREATE TABLE "sys_dict_data" ( |
| 52 | 52 | PRIMARY KEY ("id") |
| 53 | 53 | ) COMMENT '字典数据表'; |
| 54 | 54 | |
| 55 | -CREATE TABLE "sys_role" ( | |
| 55 | +CREATE TABLE IF NOT EXISTS "sys_role" ( | |
| 56 | 56 | "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, |
| 57 | 57 | "name" varchar(30) NOT NULL, |
| 58 | 58 | "code" varchar(100) NOT NULL, |
| ... | ... | @@ -70,7 +70,7 @@ CREATE TABLE "sys_role" ( |
| 70 | 70 | PRIMARY KEY ("id") |
| 71 | 71 | ) COMMENT '角色信息表'; |
| 72 | 72 | |
| 73 | -CREATE TABLE "sys_role_menu" ( | |
| 73 | +CREATE TABLE IF NOT EXISTS "sys_role_menu" ( | |
| 74 | 74 | "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, |
| 75 | 75 | "role_id" bigint NOT NULL, |
| 76 | 76 | "menu_id" bigint NOT NULL, |
| ... | ... | @@ -82,7 +82,7 @@ CREATE TABLE "sys_role_menu" ( |
| 82 | 82 | PRIMARY KEY ("id") |
| 83 | 83 | ) COMMENT '角色和菜单关联表'; |
| 84 | 84 | |
| 85 | -CREATE TABLE "sys_menu" ( | |
| 85 | +CREATE TABLE IF NOT EXISTS "sys_menu" ( | |
| 86 | 86 | "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, |
| 87 | 87 | "name" varchar(50) NOT NULL, |
| 88 | 88 | "permission" varchar(100) NOT NULL DEFAULT '', | ... | ... |