I’m working on a web application using Java Play Framework 2.0 that heavily relies on databases. I want to start writing functional tests for it that will need to access a database that has data in it already, but I don’t want it to touch the database for the actual application, and I want the test database to be reset between tests. How could I set this up and access it for a Play application?
I’m working on a web application using Java Play Framework 2.0 that heavily relies
Share
I never worked with Java Play, but the concept of database testing is commonly known across all kinds of languages. From my point of view, there are three solutions to use
Create a separate database, that is not in production and let your tests run against that database. The pro is definitely, that you are testing your code against real data. The con is to import fresh data once in a while and keep track of schema changes
You could import a clean database with just structure and some predefined figures, that will be reset before each test suite/case
The most preferable way is to use Mockup objets. That only works under the assumption, that you are using a ORM framework, so that you can capsulate.
Some links for further research
http://mockrunner.sourceforge.net (mocking supported for jdbc)
http://code.google.com/p/mockito/ (for general mocking)