Skip to content

Commit 930c445

Browse files
committed
翻译42.3.8 自动配置的Data JPA测试
1 parent 93ffe1c commit 930c445

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
###42.3.8 自动配置的Data JPA测试
1+
### 42.3.8 自动配置的Data JPA测试
2+
23
你可以使用`@DataJpaTest`测试JPA应用,它默认配置一个内存型的内嵌数据库,扫描`@Entity`类,并配置Spring Data JPA仓库,其他常规的`@Component` beans不会加载进`ApplicationContext`
34

45
Data JPA测试类是事务型的,默认在每个测试结束后回滚,具体查看Spring参考文档的[相关章节](http://docs.spring.io/spring/docs/5.0.0.RC2/spring-framework-reference/htmlsingle#testcontext-tx-enabling-transactions)。如果这不是你想要的结果,可以通过禁用事务管理器来改变:
@@ -17,7 +18,7 @@ public class ExampleNonTransactionalTests {
1718

1819
}
1920
```
20-
Data JPA测试类可能会注入一个专为测试设计的`[TestEntityManager](https://github.com/spring-projects/spring-boot/tree/v1.4.1.RELEASE/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/TestEntityManager.java)` bean以替换标准的JPA `EntityManager`。如果想在`@DataJpaTests`外使用`TestEntityManager`,你可以使用`@AutoConfigureTestEntityManager`注解。如果需要,`JdbcTemplate `也是可用的。
21+
Data JPA测试类可能会注入一个专为测试设计的[`TestEntityManager`](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M2/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/TestEntityManager.java)bean以替换标准的JPA `EntityManager`。如果想在`@DataJpaTests`外使用`TestEntityManager`,你可以使用`@AutoConfigureTestEntityManager`注解。如果需要,`JdbcTemplate `也是可用的。
2122
```java
2223
import org.junit.*;
2324
import org.junit.runner.*;
@@ -56,4 +57,4 @@ public class ExampleRepositoryTests {
5657

5758
}
5859
```
59-
[附录](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#test-auto-configuration)中可以查看`@DataJpaTest`开启的自动配置列表。
60+
[附录](https://docs.spring.io/spring-boot/docs/2.0.0.M2/reference/htmlsingle/#test-auto-configuration)中可以查看`@DataJpaTest`开启的自动配置列表。

0 commit comments

Comments
 (0)