潘志宝
2024-11-21 70079bd0772207e88414176f5ca9edb3dd4bd236
提交 | 用户 | 时间
e7c126 1 package com.iailab.framework.test.core.ut;
H 2
3 import com.iailab.framework.datasource.config.IailabDataSourceAutoConfiguration;
4 import com.iailab.framework.mybatis.config.IailabMybatisAutoConfiguration;
5 import com.iailab.framework.redis.config.IailabRedisAutoConfiguration;
6 import com.iailab.framework.test.config.RedisTestConfiguration;
7 import com.iailab.framework.test.config.SqlInitializationTestConfiguration;
8 import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
9 import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration;
10 import org.redisson.spring.starter.RedissonAutoConfiguration;
11 import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
12 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
13 import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
14 import org.springframework.boot.test.context.SpringBootTest;
15 import org.springframework.context.annotation.Import;
16 import org.springframework.test.context.ActiveProfiles;
17 import org.springframework.test.context.jdbc.Sql;
18
19 /**
20  * 依赖内存 DB + Redis 的单元测试
21  *
22  * 相比 {@link BaseDbUnitTest} 来说,额外增加了内存 Redis
23  *
24  * @author iailab
25  */
26 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = BaseDbAndRedisUnitTest.Application.class)
27 @ActiveProfiles("unit-test") // 设置使用 application-unit-test 配置文件
28 @Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) // 每个单元测试结束后,清理 DB
29 public class BaseDbAndRedisUnitTest {
30
31     @Import({
32             // DB 配置类
33             IailabDataSourceAutoConfiguration.class, // 自己的 DB 配置类
34             DataSourceAutoConfiguration.class, // Spring DB 自动配置类
35             DataSourceTransactionManagerAutoConfiguration.class, // Spring 事务自动配置类
36             DruidDataSourceAutoConfigure.class, // Druid 自动配置类
37             SqlInitializationTestConfiguration.class, // SQL 初始化
38             // MyBatis 配置类
39             IailabMybatisAutoConfiguration.class, // 自己的 MyBatis 配置类
40             MybatisPlusAutoConfiguration.class, // MyBatis 的自动配置类
41
42             // Redis 配置类
43             RedisTestConfiguration.class, // Redis 测试配置类,用于启动 RedisServer
44             IailabRedisAutoConfiguration.class, // 自己的 Redis 配置类
45             RedisAutoConfiguration.class, // Spring Redis 自动配置类
46             RedissonAutoConfiguration.class, // Redisson 自动配置类
47     })
48     public static class Application {
49     }
50
51 }