Skip to content
Advertisement

Mocking Unirest with mockito

I am in my starting programming phase and I wanted to ask about mocking Objects with Mockito, more specifically is the Unirest response. Let’s say I have a database, and I dont what to bother it every time I do testing, and I want to use Mockito for that, but the problem is I am not sure how to create the fake “httpResponse” object that will come back. To give some context, I have attached my code:

JavaScript

So what I had in mind, is to mock Unirest, and then when a .get method gets invoked, I would return a fake HttpResponse, problem is, I am not sure how to, I have looked online and couldn’t really make much sense of it. Is it possible to do it 1 time with the actual Database, and then “Extract” the information and to use that every time for testing?

Advertisement

Answer

Sample Snippet with PowerMockRunner, PowerMockito and Mockito

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement