0

I have a suite of tests that make db calls (via spring-data-jpa) and assert the result against an in memory database (mariadb4j).

Before every test, it restarts the spring context providing me with a new spring context and database every time and I can parallelise this process without any harm as each test has it's own context and can run separately.

However, what I would really like is not to have to start a spring application for each test since all the test is doing is using interfaces extending CrudRepository to insert to the db and make assertions.

I tried only recreating the datasource bean and couldn't get it working (but even if I could, I don't think it's a valid solution when parallelising tests)

I look forward to hearing your suggestions

Ali H
  • 362
  • 7
  • 19
  • If you use Maven you could run tests in parallel with `maven-surefire-plugin`: https://stackoverflow.com/questions/423627/running-junit-tests-in-parallel-in-a-maven-build And instead of recreating Spring context for each test you could try to use separate datasets: Test1 uses data for January 1st (or ID=1), Test2 uses January 2nd (or ID=2) and so on. – Ivan Feb 16 '18 at 14:22
  • @Ivan running tests in parallel is not the main issue. I want each test to point at it's own instance of the database – Ali H Feb 16 '18 at 14:26
  • For in memory database for tests you could try to use `@Scope("prototype")` for datasource. https://stackoverflow.com/questions/7621920/scopeprototype-bean-scope-not-creating-new-bean But it will require changes in how you use datasource in your classes – Ivan Feb 16 '18 at 16:43

0 Answers0