jeudi 5 mars 2015

Dropwizard Integrated Testing with Mocks for DB

First: Yes I read this http://ift.tt/1w4H7z9


I want to do some integration testing and tahts why I have to start the entire application. Now the problem is, that I have some interfaces to the "outside world" like DB or one internal Rest-Client, who speaks with one remote app. I want to mock them with mockito. Normally thats no problem.


Now my question: How can I start entire application with mocked DB and mocked client?


The problem at the moment is, that I get this DB connection and client from my configuration class via getDBClient() ... and I'm not willing to build in some test code in my config, because its production code. So if I start the entire app via DropwizardAppRule, the app tries to connect to database, but in testing enviroment, there is no DB available.


Is there a easy way to say: Start my app but if you call DB or client, then use this XY mock?


What I tried yet: One new class "ExtendedService extends Service extends Application" and one "ExtServiceConfiguration extends ServiceConfiguration", but without any success. But I having trouble if I override some methods in the config class returning the mock. It does not fit all together.


At the moment I read the docs for mockito spy, perhaps this can help, but I'm not sure how to use this in the DW integrated tests.


Aucun commentaire:

Enregistrer un commentaire