我正在嘗試測驗 DAO 層。我將我的應用程式連接到本地 postgresql 服務器。
測驗通過并回滾資料(表在資料庫中保持為空)。
當我嘗試在測驗代碼中列印 notificationTerm.getId() 時,每次測驗執行后它都會增加 1。
但是哪一行代碼使資料回滾?
@RunWith(SpringRunner.class)
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@DataJpaTest
public class DAOIntegrationTests {
@Autowired
private TestEntityManager entityManager;
@Test
public void testNotificationTermFakeDAO() {
NotificationTerm notificationTerm = new NotificationTerm();
notificationTerm.setDays(365);
entityManager.persist(notificationTerm);
entityManager.flush();
NotificationTerm foundNotificationTerm = entityManager.find(NotificationTerm.class, notificationTerm.getId());
assertEquals(notificationTerm.getDays(), 365);
}
}
uj5u.com熱心網友回復:
當您使用時,@DataJpaTest這是默認行為。
Spring Boot Data JPA Test 正在執行測驗方法并在每個測驗方法后進行回滾。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/339855.html
上一篇:Java:集合映射中的重復列
下一篇:找不到類org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor一對一映射hibernate的序列化程式
