Mocks usage #17
Replies: 4 comments 10 replies
-
Beta Was this translation helpful? Give feedback.
-
super explanation :) But yes, it is true that the urls starting with http:// will be automatically remapped to their local mocks starting with MockFaster.url() so it could be a bit ambiguous as a feature ... maybe we could remove this to make it more intuitive ... It is currently not really possible to mock a random url since we don't control the http client used by your application. This would be possible though ... we could encapsulate the RestTemplate or WebFlux builders in the spring module ... maybe a nice feature to implement! |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
I have released the version 1.0.5 fixing all the problems raised in this thread! |
Beta Was this translation helpful? Give feedback.
-
Hello,
I would like to know more about how to mock an api call.
In my case i have to test a service (called A for example). The service A makes a call to an external api service (called B). In my tests, i would like to mock all the calls to the service B as it will not be availabed when i build my app on jenkins for example.
I tried examples from the doc by it doesn't work :
Given that calling "https://service-B" will return a status OK_200 and:
"""
some data here
"""
When a user send on "/service-A":
"""
method: POST
body:
payload:
some data here
"""
Then it receives a status CREATED_201
This doesn't work me at first because the service B is called by my service A and not directly in the tests as this example :
tzatziki/tzatziki-http/src/test/resources/com/decathlon/tzatziki/steps/http.feature
Line 3 in 6e0b97d
To resolve the issue, in my steps initializer class , i added this system env :
System.setProperty("ENDPOINT", MockFaster.url());
this variable is used by my code to make the call to B (in application-test.yaml as i'm using spring boot) :
host-service-B: ${ENDPOINT}/service-B-resource
and in the gherkin, i'm not using urls prefixed with http and https. So in the last test we have to change just the first line :
Given that calling "/service-B" will return a status OK_200 and:
Using this, all the api calls will be intercepted by the MockFaster.url() and mocked.
I don't know if this is the good way to use the library ?
If so, i think that this part have to be added to the documentation ?
Beta Was this translation helpful? Give feedback.
All reactions