0

Unit tests in Play subprojects using a database fail due to this Error:

javax.persistence.PersistenceException: The default EbeanServer has not been defined? This is normally set via the ebean.datasource.default property. Otherwise it should be registered programatically via registerServer()

It is thrown when doing something like this:

MyEntity entity = new MyEntity();
entity.save();

Also

server = Ebean.getServer("default");

won't work either -It would cause this error: java.lang.RuntimeException: DataSource user is null?

The only (very ugly) workaround that I have found is to move the Unit Test to the root Play project that hosts the subproject, which contains the model classes (MyEntity).

Has anybody an idea how to get the unit test working in the subproject?

user3271386
  • 35
  • 1
  • 5
  • Please keep in mind that unit-testing usually requires abstracting database access behind a repository interface. This allows for easy mocking and unit-testing without a live database or running application. See 'Unit testing models': https://www.playframework.com/documentation/2.3.x/JavaTest. (This was an answer before, but @user3271386 was right that this is more of a guess/hint about possible architectural problems than an actual solution for sub-projects) – Blacklight Jan 16 '15 at 07:31

1 Answers1

0

Try setting evolutionplugin=enabled

Prerak Sola
  • 9,517
  • 7
  • 36
  • 67