Integration Testing with a fake server

天涯浪子 提交于 2019-12-24 17:26:02

问题


I have a service which connects to a set of api's which i want to test.

I would like to make a Fake Service for my integration tests (to simulate failure situations)

I cannot simply use @RestController as they are not loaded during a test, and I looked into mockserver but I am unsure if it is what I am looking for, as I do not want my test to trigger a mock call, but rather my code should trigger the api call normally, simply using the mock server rather than an actual server (the base url is configurable so i can make my service point to a mock server)

UPDATE 1:

The only alternative I am seeing is possibly launching Cargo and deploying my service inside it?

UPDATE 2: I just found out about Wiremock. Could this be usable here?


回答1:


I went with WireMock http://wiremock.org/

Setting the ClassRule in a junit test will have the fake server up and running before your test starts.




回答2:


Mockito(http://docs.mockito.googlecode.com/hg/1.9.5/org/mockito/Mockito.html) is a good library for mocking method calls. It can return a certain value given a certain input. With this library you could mock a REST client to simulate the communication between your application and the REST api.



来源:https://stackoverflow.com/questions/36702471/integration-testing-with-a-fake-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!