解决 redis 和 mysql 在单元测试会报错的问题
parent
3320f42bd7
commit
e9f2e91f7e
|
@ -1,18 +1,16 @@
|
||||||
package cn.iocoder.dashboard.config;
|
package cn.iocoder.dashboard.config;
|
||||||
|
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.quartz.impl.StdScheduler;
|
import org.quartz.Scheduler;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Lazy;
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Lazy(false)
|
|
||||||
public class QuartzTestConfiguration {
|
public class QuartzTestConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public StdScheduler scheduler() {
|
public Scheduler scheduler() {
|
||||||
return Mockito.mock(StdScheduler.class);
|
return Mockito.mock(Scheduler.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import org.springframework.context.annotation.Lazy;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@Lazy(false) // 禁用懒加载,因为需要保证 Redis Server 必须先启动
|
@Lazy(false) // 禁用懒加载,因为需要保证 Redis Server 必须先启动
|
||||||
@EnableConfigurationProperties(RedisProperties.class)
|
@EnableConfigurationProperties(RedisProperties.class)
|
||||||
@AutoConfigureBefore({RedisAutoConfiguration.class, RedissonAutoConfiguration.class}) // 在 Redis 自动配置前,进行初始化
|
@AutoConfigureBefore({RedisAutoConfiguration.class, RedissonAutoConfiguration.class}) // 在 Redis 自动配置前,进行初始化
|
||||||
|
@ -32,6 +32,7 @@ public class RedisTestConfiguration {
|
||||||
@Bean(destroyMethod = "stop")
|
@Bean(destroyMethod = "stop")
|
||||||
public RedisServer redisServer(RedisProperties properties) throws IOException {
|
public RedisServer redisServer(RedisProperties properties) throws IOException {
|
||||||
RedisServer redisServer = new RedisServer(properties.getPort());
|
RedisServer redisServer = new RedisServer(properties.getPort());
|
||||||
|
// TODO 芋艿:一次执行多个单元测试时,貌似创建多个 spring 容器,导致不进行 stop。这样,就导致端口被占用,无法启动。。。
|
||||||
try {
|
try {
|
||||||
redisServer.start();
|
redisServer.start();
|
||||||
} catch (Exception ignore) {}
|
} catch (Exception ignore) {}
|
||||||
|
|
|
@ -1,25 +1,20 @@
|
||||||
package cn.iocoder.dashboard.modules.tool.dal.mysql.codegen;
|
package cn.iocoder.dashboard.modules.tool.dal.mysql.codegen;
|
||||||
|
|
||||||
|
import cn.iocoder.dashboard.BaseSpringBootUnitTest;
|
||||||
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolSchemaColumnDO;
|
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolSchemaColumnDO;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
|
||||||
import org.springframework.test.context.jdbc.Sql;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
@SpringBootTest
|
public class ToolInformationSchemaColumnMapperTest extends BaseSpringBootUnitTest {
|
||||||
@ActiveProfiles("unit-test")
|
|
||||||
public class ToolInformationSchemaColumnMapperTest {
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ToolSchemaColumnMapper toolInformationSchemaColumnMapper;
|
private ToolSchemaColumnMapper toolInformationSchemaColumnMapper;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
|
|
||||||
public void testSelectListByTableName() {
|
public void testSelectListByTableName() {
|
||||||
List<ToolSchemaColumnDO> columns = toolInformationSchemaColumnMapper
|
List<ToolSchemaColumnDO> columns = toolInformationSchemaColumnMapper
|
||||||
.selectListByTableName("inf_config");
|
.selectListByTableName("inf_config");
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
package cn.iocoder.dashboard.modules.tool.dal.mysql.codegen;
|
package cn.iocoder.dashboard.modules.tool.dal.mysql.codegen;
|
||||||
|
|
||||||
|
import cn.iocoder.dashboard.BaseSpringBootUnitTest;
|
||||||
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolSchemaTableDO;
|
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolSchemaTableDO;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
@SpringBootTest
|
class ToolInformationSchemaTableMapperTest extends BaseSpringBootUnitTest {
|
||||||
class ToolInformationSchemaTableMapperTest {
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ToolSchemaTableMapper toolInformationSchemaTableMapper;
|
private ToolSchemaTableMapper toolInformationSchemaTableMapper;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package cn.iocoder.dashboard.modules.tool.service.codegen.impl;
|
package cn.iocoder.dashboard.modules.tool.service.codegen.impl;
|
||||||
|
|
||||||
|
import cn.iocoder.dashboard.BaseSpringBootUnitTest;
|
||||||
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenColumnDO;
|
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenColumnDO;
|
||||||
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenTableDO;
|
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolCodegenTableDO;
|
||||||
import cn.iocoder.dashboard.modules.tool.dal.mysql.codegen.ToolCodegenColumnMapper;
|
import cn.iocoder.dashboard.modules.tool.dal.mysql.codegen.ToolCodegenColumnMapper;
|
||||||
|
@ -11,8 +12,7 @@ import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@SpringBootTest
|
public class ToolCodegenEngineTest extends BaseSpringBootUnitTest {
|
||||||
public class ToolCodegenEngineTest {
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ToolCodegenTableMapper codegenTableMapper;
|
private ToolCodegenTableMapper codegenTableMapper;
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
package cn.iocoder.dashboard.modules.tool.service.codegen.impl;
|
package cn.iocoder.dashboard.modules.tool.service.codegen.impl;
|
||||||
|
|
||||||
|
import cn.iocoder.dashboard.BaseSpringBootUnitTest;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
public class ToolCodegenSQLParserTest extends BaseSpringBootUnitTest {
|
||||||
|
|
||||||
class ToolCodegenSQLParserTest {
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParse() {
|
public void testParse() {
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package cn.iocoder.dashboard.modules.tool.service.codegen.impl;
|
package cn.iocoder.dashboard.modules.tool.service.codegen.impl;
|
||||||
|
|
||||||
|
import cn.iocoder.dashboard.BaseSpringBootUnitTest;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
@SpringBootTest
|
class ToolCodegenServiceImplTest extends BaseSpringBootUnitTest {
|
||||||
class ToolCodegenServiceImplTest {
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ToolCodegenServiceImpl toolCodegenService;
|
private ToolCodegenServiceImpl toolCodegenService;
|
||||||
|
|
|
@ -31,7 +31,7 @@ spring:
|
||||||
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
|
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
|
||||||
redis:
|
redis:
|
||||||
host: 127.0.0.1 # 地址
|
host: 127.0.0.1 # 地址
|
||||||
port: 36379 # 端口(单元测试,使用 363979 端口)
|
port: 16379 # 端口(单元测试,使用 16379 端口)
|
||||||
database: 0 # 数据库索引
|
database: 0 # 数据库索引
|
||||||
|
|
||||||
--- #################### 定时任务相关配置 ####################
|
--- #################### 定时任务相关配置 ####################
|
||||||
|
|
Loading…
Reference in New Issue