# 43.3.12 自动配置的jOOQ测试

`@JooqTest`的使用方式同`@JdbcTest`相似，不过是给jOOQ相关的测试用的。由于jOOQ严重依靠与数据库模式相对应的基于Java的模式，既存的`DataSource`将会被使用。如果你想要用一个内存数据库代替它，你可以使用`@AutoconfigureTestDatabase`来覆盖那些设置。（在Spring Boot里使用jOOQ的更多信息，请查看[章节 29.5 使用jOOQ](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-jooq)。）

`@JooqTest`将会配置一个`DSLContext`。常规的`@Component`bean将不会加载进`ApplicationContext`。下面的例子展示了使用中的`@JooqTest`注解：

```java
import org.jooq.DSLContext;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.autoconfigure.jooq.JooqTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@JooqTest
public class ExampleJooqTests {

    @Autowired
    private DSLContext dslContext;
}
```

JOOQ测试类是事务型的，默认在每个测试结束时回滚。如果这不是你想要的结果，你可以按照[JDBC例子中的方式](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-testing-spring-boot-applications-testing-autoconfigured-jdbc-test)对一个测试或是整个类禁用事务管理。

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jack80342.gitbook.io/spring-boot/iv.-spring-boot-features/43.-testing/43.3-testing-spring-boot-applications/43.3.12-auto-configured-jooq-tests.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
