I want to unit test my code without a dependency on having the back end service up and running on my google app engine. What is the best way to achieve this without having to create my own implementation of every class like the Request factory etc.
Here is my code. I have hacked the Util class to return a mock MyRequestFactory instance when running unit tests. This mock factory then returns mock implementation of MyRequest.
This in turn has mock implementations of the create, update delete etc. methods.
Problem is I have many more entities that I need to do this with and will end up with a huge amount of mock classes.
Is there an easier way? Which mocking framework do you think would suit best?
MyRequestFactory requestFactory = Util.getRequestFactory(mContext,
MyRequestFactory.class);
final MyRequest request = requestFactory.myRequest();
BookProxy bookProxy = request.create(BookProxy.class);
bookProxy.setDescription(bookDescription.getText().toString());
bookProxy.setName(bookName.getText().toString());
Log.i(TAG, "Adding book" + bookProxy.toString());
Request<bookProxy> sendRequest = request.updateBook(bookProxy);
sendRequest.fire();
bookName.setText("");
bookDescription.setText("");
I prefer Mockito for mocking as it allows spys and post execution expectation / verification.
Also, Powermock allows things such as mocking static methods and calls to constructors.