1

When runnning tests in PlayFramework, you expect the database to be cleared before every test (for true isolation) and evolutions to be played, but somehow that doesn't seem to be the case.

How can I clear the database before running every test in general, or if there is no general approach, when using anorm?

EDIT : I already know the H2 - MODE for testing even with database specifics but as said in comment below, what I want is have the same testing and production database setup. In order to do that, I need to be able to reload my DB before each test.

i.am.michiel
  • 10,281
  • 7
  • 50
  • 86
  • possible duplicate of [How to create unit tests against non in-memory database such as MySQL in Play framework, with resetting to known state?](http://stackoverflow.com/questions/14750375/how-to-create-unit-tests-against-non-in-memory-database-such-as-mysql-in-play-fr) - Voted to close since the linked-to answer seems to contain the answer you need :) – fresskoma Apr 02 '13 at 07:37
  • I've seen that answer/question but it seems to be Java & Ebean related. I'm using `anorm`. – i.am.michiel Apr 02 '13 at 07:53

1 Answers1

-2

Run the tests on a inmemory Database. Check http://www.playframework.com/documentation/2.0/ScalaTest for an example on how its done. That way, the db will be initiated from evolutions before each test and only data that you want specific for that test needs to be added or whatnot.

Jakob
  • 751
  • 4
  • 17
  • As a matter of fact, what you suggest is a workaround using the inMemory database. I am already using that solution for the moment but what I really would like to do is to use the same database setup for testing as for my prouction servers. And to do that, I need to reload my DB after each test. – i.am.michiel Apr 02 '13 at 09:49
  • When you say you want the same setup, do you mean that you want prod data in the database when you run the tests? Basically an exact copy of your prod db at some point in time and then reset to that point before each test? – Jakob Apr 02 '13 at 10:11
  • No, no. A simple example would be server encoding-settings, connection triggers, connection pool and so on. I am really talking about server configuration. – i.am.michiel Apr 02 '13 at 10:36