I try to do some JUnit tests in PlayFramework 2.3.8. I have to do this test in memory database, so that I keep the "real" database untouched. I have done this:
PublicType SaveToolsTest withApplication Extended {@Before public void startApp () {// Start the app in the Memory Database Map & lt; String, string & gt; Settings = New Hashmop & lt; String, string & gt; (); Settings.put ("db.default.url", "jdbc: h2: mem: play"); Settings.put ("db.default.user", ""); Settings.put ("db.default.password", ""); App = helpers. Apk application (settings); Helpers.start (app); } @Test Public Null save user () {user user = createUser (); // Save the user in DB Ebean.save (user); // test if user! = Null assertNotNull (user); AssertThat (user.id) .isNotNull (); }
But by doing so, I connect the test to the actual DB. How can I add it to memory db?
In Play 2.3 and above, you can specify the Fake test while overriding the application () method Play (and its settings like used databases) Play will call this method and start the application that you came back before running your tests.
Import play.test. *; Static play.test.Helpers Import. *; Public Class Mitest With Application {@ Override Public Faces Applications Provide Facebook Application ()} First Appointment (InMery Database ()); } @Test Public Zero myTest () {// Your Test Here}
No comments:
Post a Comment