Reputation: 7519
Our database is a postgresql. We use the JPA to manage our persistence tasks. Currently, our tests require the presence of a postgres server in order to execute. This makes our running our tests on a dev box as hassle, because the dev has to first install a postgres server, and it makes portability to various build server environments, from CI to our release build environment, difficult.
It seems to me that I should be able to switch out the heavy weight db server for a lightweight in memory version. We dont do any postgres specific things. Our code is mostly pure JPA with a touch of hibernate specific functionality accessed.
Upvotes: 0
Views: 203
Reputation: 14520
you have two possibilities. you can set up separated postgres database and make your CI code connect to it. however, often it is not necessary. if your database code doesn't use very postgres specific features, think about using other, in-memory database. eg. h2 or hsqldb. you can even change your code a bit to make it more portable, if needed. the second option is of course a bit more risky, as there is always a chance that your code will work on in-memory db but not on postgres. the first option however may require a bit more administration and maintenance.
Upvotes: 0
Reputation: 30022
You can dependency inject your database into code you need to unit test. If your code already has dependencies on postgressql that are hard to inject you can use PowerMock to replace any static or constructor methods you call to return fakes that you control.
The fake database you return can be as simple as a hashtable with preset values depending on what you need to test.
Upvotes: 1