Closed shakyasudeep closed 3 years ago
Hi, @shakyasudeep Spring MockRestServiceServer is a great tool, but it only works with Spring RestTemplate. It binds itself to the insides of a RestTemplate instance and intercepts the calls. It's never going to work with Unirest (or Apache Client, or Feign, or etc)
It's a little weird you would post this today because this last weekend we released as part of Unirest it's own dedicated mocking layer. It's still young and not as robust or mature as Spring's mock but it might get you by/ Any feedback is welcome
https://github.com/Kong/unirest-java/tree/main/unirest-mocks
Hi, @shakyasudeep Spring MockRestServiceServer is a great tool, but it only works with Spring RestTemplate. It binds itself to the insides of a RestTemplate instance and intercepts the calls. It's never going to work with Unirest (or Apache Client, or Feign, or etc)
It's a little weird you would post this today because this last weekend we released as part of Unirest it's own dedicated mocking layer. It's still young and not as robust or mature as Spring's mock but it might get you by/ Any feedback is welcome
https://github.com/Kong/unirest-java/tree/main/unirest-mocks
Thanks for the reply @ryber . I was not aware about unirest-mocks
. I will try with unirest-mocks
.
I'm going to go ahead and close this.
I'm going to go ahead and close this.
OK.
I have used
Unirest
library for calling third party APIs in my services,it works fine but fails when writing test cases. But I also need to test the Service classes which calls the third party APIs, I have tried to test the services but it usually fails. How to test a service that usesUnirest
library to call the APIs ? I am usingSpring Boot
and posting my code of the service and the test cases.Service class method :
Test class method :
The test case fails at
mockServer.verify();
. Is usingRestTemplate
wrong idea for testingUnirest
? Or is there anything wrong in my code ? Please suggest how to move forward. Is there any separate library to testUnirest
based services ? @ryber @subnetmarco