Transactions in Spring testing

table of Contents

Article Directory

@Transactional

1. The transaction is automatically rolled back after the annotation is added to the test method.
2. @BeforeEach and @AfterEach are executed in the transaction of the test method.
3. @BeforeTransactional and @AfterTransactional are executed before and after the transaction; and the test method without @Transactional does not execute the methods under these two annotations.
4. The propagation behavior is only REQUIRED and NOT_SUPPOREED.
5. The use of RANDOM_PORT or DEFINED_PORT implicitly provides a real servlet environment, so the HTTP client and server will run in separate threads and thus separate transactions . In this case, any transactions started on the server will not be rolled back.

Guess you like

Origin blog.csdn.net/qq_43621091/article/details/107070996