1234567891011121314151617181920212223242526272829303132 |
- package cn.iocoder.dashboard;
- import org.junit.jupiter.api.AfterEach;
- import org.springframework.boot.test.context.SpringBootTest;
- import org.springframework.data.redis.core.RedisCallback;
- import org.springframework.data.redis.core.StringRedisTemplate;
- import org.springframework.test.context.ActiveProfiles;
- import org.springframework.test.context.jdbc.Sql;
- import javax.annotation.Resource;
- @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
- @ActiveProfiles("unit-test") // 设置使用 application-unit-test 配置文件
- @Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) // 每个单元测试结束后,清理 DB
- @Deprecated
- public class BaseSpringBootUnitTest {
- @Resource
- private StringRedisTemplate stringRedisTemplate;
- /**
- * 每个单元测试结束后,清理 Redis
- */
- @AfterEach
- public void cleanRedis() {
- stringRedisTemplate.execute((RedisCallback<Object>) connection -> {
- connection.flushDb();
- return null;
- });
- }
- }
|