You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: IV. Spring Boot features/42.3.8 Auto-configured Data JPA tests.md
+4-3Lines changed: 4 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,5 @@
1
-
###42.3.8 自动配置的Data JPA测试
1
+
### 42.3.8 自动配置的Data JPA测试
2
+
2
3
你可以使用`@DataJpaTest`测试JPA应用,它默认配置一个内存型的内嵌数据库,扫描`@Entity`类,并配置Spring Data JPA仓库,其他常规的`@Component` beans不会加载进`ApplicationContext`。
3
4
4
5
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 {
17
18
18
19
}
19
20
```
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 `也是可用的。
21
22
```java
22
23
importorg.junit.*;
23
24
importorg.junit.runner.*;
@@ -56,4 +57,4 @@ public class ExampleRepositoryTests {
0 commit comments