Currently we are using paymentintent.New() method to create a payment intent for stripe but the issue we are facing is in writing unit tests (for integration test, we are already aware of stripe-mock)
Inside this method, a http client is created internally. Not sure how can we mock it.
https://github.com/stripe/stripe-go/blob/master/paymentintent/client.go#L24
We have tried generating the mock of stripe http client by ourselves but that won't help much since paymentintent internally creates a HTTP client and we don't see a way to pass our own http client inside the paymentintent method
stripe-go is using stripe-mock internally for unit testing. You can see this piece of code to learn how to set a mock server for you unit tests.
Related
While developing a web application I have the following use case:
a 3rd party Web Service with quite a lot of methods is deployed on a test server A (with a single endpoint, e.g. http://3rdPartyServer/3rdPartySvc?WSDL)
a new method is about to be implemented in the near future, but I need to use it now
the rest of the methods are used throughout my code extensively
So I would like to do the following:
Create a mock service in SoapUI locally, based on the new WSDL which includes the new WS method (i.e. a superset of the WS methods currently on server A)
point my local application server to use the SoapUI mock service endpoint
mock only the response of the new WS method (create a dummy response for it in SoapUI)
let the other WS method calls to reach server A and return whatever it returns normally (i.e. use SoapUI as a proxy for these calls)
I've gone through the SoapUI documentation regarding service mocking and have used it numerous times, but could not find an option for such "pass-through" behavior.
When you read in your WSDL, the endpoint will point to your server.
Open your service, and select the service endpoint.
Add a second endpoint, to point to your mock. SoapUI has little bit of documentation showing this here. Only step "2. Getting Started" applies, not step 3!
In each of your tests, where you are using the mocked method, you will need to select the mock endpoint. Further discussion is here.
I have a grails 2.3.x webapp that uses CXF to call to backend SOAP services. I'd like to set up a test where I call my service, but provide the response back from the service as a string directly to test it.
So, I want to set up a test that will autowire the service. I then set the response somehow as a string. Call the service method under test and under the covers it receives the response string I set and the request is ignored (or possibly even could check its validity). It parses the response which goes through the service code and returns as usual.
I don't want to have to run a separate server for the test. Is there someway to put in the response directly?
I wrote an simple HTTP utility class, which takes a HTTP method name and a requesting URL then return the response.
In my Grails app, several Services will use this utility to get results of some Web API calls. However, I don't know how to unit test these Services. The utility is so simple that it only uses HttpURLConnection to execute HTTP requests, no any other dependencies.
How should I unit test these Services? Should I make the utility as a property of the Services, so that this utility can be injected and mocked on them?
Any suggestions?
You can create a MockHttpUtility, and then use it for test environment.
You can modify resources.groovy so that for tests, the mockService will be injected in your services/controllers instead of real service.
switch(GrailsUtil.environment) {
case "test":
httpUtil(MockHttpUtil) {bean ->
bean.autowire = "byName"
}
}
This would work for integration tests.
For unit tests, you can define the mock service as below
void testFoo() {
defineBeans {
httpUtil(MockHttpUtil)
}
}
You can design mock http util such that it returns the expected response when called. Eg, you can have a constructor or a setter that will take the expected response, and when the utility method is called with http method and url, it will return the given response.
I have a service that has a method that makes a rest call using apache httpclient. I want to test the call using junit but i do not want to mock out the call but mock out the server that it is making the call to
My question is, is it possible to mock out a server using something like mockwebserver so that if you make a request to a specific url that this will be picked up from the service (without mocking the service) rather then going off to the real server?
HttpClient is an interface so you can return a mock in your tests.
Try Jadler (http://jadler.net), an open source library for creating stub/mock http servers. It should provide you everything you need (I'm one of its developers).
I am using RestBuilder (LINK) for making REST calls to outer services.
Now I want to mock that http requests for unit testing (or integration testing, whatever) service that handles all logic about communication with that outer services.
Does anyone know how to mock http requests or this RestBuilder maybe?
Thanks for any help!
Ivan
This kind of test is called «functional test». There are many plugins that can help you with this task:
http://www.grails.org/plugin/functional-test
http://www.grails.org/plugins/tag/functional