3

Spring Boot Parent - 2.0.5.RELEASE

I have few integration tests in order:

  1. Test class which uses @MockBean annotation for some dependencies therefore I have got @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) on class
  2. Another test class which uses db (let's say making some select using JpaRepository in h2 which is fully managed by spring)

First test passes, but second has got exceptions: Caused by: org.hibernate.exception.SQLGrammarException: could not prepare statement Caused by: org.h2.jdbc.JdbcSQLException: Table "x" not found; SQL statement:

It seems like db is created, but DDL wasn't done.

How can I solve this problem?

For sure I can add in second test an annotation @AutoConfigureTestDatabase, but I feel it is wrong to add this annotation on every test class which uses db after tests with @DirtiesContext.

mat.mik
  • 97
  • 1
  • 8
  • database should be initialized success. Did your tests works if you running their by one? – borino Oct 05 '18 at 10:05
  • yes, it works properly (either one by one or run in opposite order) – mat.mik Oct 05 '18 at 14:21
  • In this case you can easily add test method ordering [sample](https://stackoverflow.com/questions/3693626/how-to-run-test-methods-in-specific-order-in-junit4). Otherwise need more details for example project sample on git hub. – borino Oct 08 '18 at 05:23

0 Answers0