> For the complete documentation index, see [llms.txt](https://jack80342.gitbook.io/spring-boot/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jack80342.gitbook.io/spring-boot/iv.-spring-boot-features/43.-testing/43.3-testing-spring-boot-applications/43.3.15-auto-configured-data-redis-tests.md).

# 43.3.15 自动配置的Data Redis测试

你可以使用`@DataRedisTest`测试Redis应用。默认的，它将会扫描`@RedisHash`类和配置Spring Data Redis仓库。常规的`@Component`bean将不会加载进`ApplicationContext`。（在Spring Boot里使用Redis的更多信息，请查看[章节 30.1 Redis](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-redis)。）

下面的例子展示了使用中的`@DataRedisTest`注解：

```java
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.data.redis.DataRedisTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@DataRedisTest
public class ExampleDataRedisTests {

    @Autowired
    private YourRepository repository;

    //
}
```

在[附录](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#test-auto-configuration)中可以查看`@DataRedisTest`开启的自动配置列表。
