Skip to content

Commit 75469aa

Browse files
committed
翻译42.3.9 自动配置的JDBC测试
1 parent cbcbe37 commit 75469aa

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

IV. Spring Boot features/42.3.8 Auto-configured Data JPA tests.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
你可以使用`@DataJpaTest`测试JPA应用,它默认配置一个内存型的内嵌数据库,扫描`@Entity`类,并配置Spring Data JPA仓库,其他常规的`@Component` beans不会加载进`ApplicationContext`
44

5-
Data JPA测试类是事务型的,默认在每个测试结束后回滚,具体查看Spring参考文档的[相关章节](http://docs.spring.io/spring/docs/5.0.0.RC2/spring-framework-reference/htmlsingle#testcontext-tx-enabling-transactions)。如果这不是你想要的结果,可以通过禁用事务管理器来改变
5+
Data JPA测试类是事务型的,默认在每个测试结束时回滚,具体查看Spring参考文档的[相关章节](http://docs.spring.io/spring/docs/5.0.0.RC2/spring-framework-reference/htmlsingle#testcontext-tx-enabling-transactions)。如果这不是你想要的结果,你可以按如下方式对一个测试或是整个类禁用事务管理
66
```java
77
import org.junit.Test;
88
import org.junit.runner.RunWith;

IV. Spring Boot features/42.3.9 Auto-configured JDBC tests.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
###42.3.9 自动配置的JDBC测试
2-
@JdbcTest is similar to @DataJpaTest but for pure jdbc-related tests. By default it will also configure an in-memory embedded database and a JdbcTemplate. Regular @Component beans will not be loaded into the ApplicationContext.
1+
### 42.3.9 自动配置的JDBC测试
32

4-
JDBC tests are transactional and rollback at the end of each test by default, see the relevant section in the Spring Reference Documentation for more details. If that’s not what you want, you can disable transaction management for a test or for the whole class as follows:
3+
`@JdbcTest``@DataJpaTest`相似,不过是给纯jdbc相关的测试用的。默认的,它将会配置一个内存数据库和一个`JdbcTemplate`。常规的`@Component`bean将不会加载进`ApplicationContext`
54

5+
JDBC测试类是事务型的,默认在每个测试结束时回滚,具体查看Spring参考文档的[相关章节](http://docs.spring.io/spring/docs/5.0.0.RC2/spring-framework-reference/htmlsingle#testcontext-tx-enabling-transactions)。如果这不是你想要的结果,你可以按如下方式对一个测试或是整个类禁用事务管理:
6+
```java
67
import org.junit.Test;
78
import org.junit.runner.RunWith;
89
import org.springframework.boot.test.autoconfigure.jdbc.JdbcTest;
@@ -16,6 +17,7 @@ import org.springframework.transaction.annotation.Transactional;
1617
public class ExampleNonTransactionalTests {
1718

1819
}
19-
If you prefer your test to run against a real database, you can use the @AutoConfigureTestDatabase annotation the same way as for DataJpaTest.
20+
```
21+
如果你更喜欢在非真实的数据库上运行你的测试,你可以和`DataJpaTest`一样,使用`@AutoConfigureTestDatabase`注解。
2022

21-
A list of the auto-configuration that is enabled by @JdbcTest can be found in the appendix.
23+
[附录](https://docs.spring.io/spring-boot/docs/2.0.0.M2/reference/htmlsingle/#test-auto-configuration)中可以查看`@JdbcTest`开启的自动配置列表。

0 commit comments

Comments
 (0)