9

my Play using mysql in production. But I am trying to use memory for testing.

I created 2 conf file, 1 is application.conf, the other is application.test.conf (in the same directory).

I tried to do

play -Dconfig.file=conf/application.test.conf test-only

But it still use the default conf file. I'm just wonder if anyone know how to use a different conf file during testing. (or at least use a different database setting during testing).

hook38
  • 3,899
  • 4
  • 32
  • 52

1 Answers1

2

If you mean for unit tests then just add

running(FakeApplication(additionalConfiguration = inMemoryDatabase())) { Test code... }

to your tests and they will be done in memory. No need to change conf files.

Jakob
  • 751
  • 4
  • 17
  • 1
    Thank you, just to clarify for other people. The syntax you gave is for Scala. In java, it's running(fakeApplication(inMemoryDatabase()), new Runnable() { – hook38 Mar 14 '13 at 23:02
  • Ah yeah. Well I had a 50/50 chance to get the language right ;) – Jakob Mar 15 '13 at 09:37
  • 1
    However if the production database is, say for example, MySQL, shouldn't we be running tests against a MySQL database to ensure there are no database specific bugs?? Especially if you're writing straight SQL via Anorm or similar. – Pete Jul 16 '13 at 13:06
  • Pete, yes that can be an issue. It depends on how complicated your db structure is. But my experience is that you can do very much this way without running into trouble. – Jakob Jul 17 '13 at 06:05
  • 4
    I think this answer is rather a workaround, it doesn't answer the original question. – Balázs Németh Nov 11 '13 at 09:55
  • I would prefer to avoid having to specify the "additionalConfiguration" many times. Using a conf file is much cleaner. – Khanetor Nov 25 '14 at 03:30