Is there a way to roll back transactions caused by queries made using RestTemplate in a test method?
No. Unable to roll back transactions managed by your deployed application.
When you comment on your test class using @WebIntegrationTest and @SpringApplicationConfiguration , Spring Boot launches the built-in Servlet container and deploys your application in it. So, in this sense, your test and application work in two different processes.
The Spring TestContext Framework manages Test Transactions . Thus, the presence of @Transactional in your test class affects only local transactions controlled by testing, and not different processes.
As mentioned earlier, the crawl will consist of resetting the database after the test completes. You have several options for this. For more information, see Executing SQL Scripts in the Reference Guide.
Hello,
Sam (author of Spring TestContext Framework)
source share