0

I am currently testing my Spring repositories and decided to use a MariaDB server instance instead of an in-memory Derby instance because of some complications in a test that involved a database view.

While the tests eventually did succeed without errors and failures, I noticed that I didn't add a @DatabaseTeardown annotation to my test case. So I decided to check my database for unwanted rows leftover from the test and found that my database was just as empty as before the test.

Could someone here explain why this is happening?

VikNop
  • 73
  • 1
  • 8

1 Answers1

0

As you said that you use @Transactional on your test cases, its default behavior is tests is to enclose entire test in a transaction and automatically rollback it, thus making sure your database is in the same state as it was before the test cases.

Check this StackOverflow answer - https://stackoverflow.com/a/9817815/1589165

This is documented here in Spring docs - http://docs.spring.io/spring/docs/current/spring-framework-reference/html/integration-testing.html#testcontext-tx

Community
  • 1
  • 1
Harshil Sharma
  • 2,016
  • 1
  • 29
  • 54