Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create A Mock Test Client #1193

Closed
meggieveggie opened this issue Sep 29, 2020 · 5 comments · Fixed by #1603
Closed

Create A Mock Test Client #1193

meggieveggie opened this issue Sep 29, 2020 · 5 comments · Fixed by #1603

Comments

@meggieveggie
Copy link

meggieveggie commented Sep 29, 2020

Proposed Feature

After implementing the Golang SDK there could possibly be a better test suite that can be created. For instance the current issue I am having is mocking a response from:

stripeClient.Invoices.List(params)

My thinking here would be to approach this how kubernetes has with their fake client. I understand there are many ways to mock out responses (This could definitely be documented better). However it seems that having the ability to do something along the lines of:

stripeClient := &stripeFakeClient{}

stripeClient.Invoices.Create(*Invoices{//Some Random Invoice Data})

resp := stripeClient.Invoices.List(params)

without actually calling the API would make integration with your platform a lot more seamless and speed up the process.

@remi-stripe
Copy link
Contributor

@meggieveggie Thanks for the feedback. We usually recommend using stripe-mock for something like this which is what we use in our test suite. You can read more about this here: https://github.com/stripe/stripe-mock/
Would that work for you?

@meggieveggie
Copy link
Author

@remi-stripe My understanding of stripe-mock is that it is specifically used for integration tests and not unit tests. If this is not the case then I will try and use stripe-mock

@ianjabour-stripe
Copy link

ianjabour-stripe commented Oct 3, 2020

@meggieveggie thank you for this suggestion. You are correct in that stripe-mock is built mainly for integration tests, but it should still allow you to quickly test your integration without actually hitting the Stripe API.

The limitation with stripe-mock is that it is stateless, so fetching objects you create in a test will not work. Also, the data made available is limited to that which we generate based off resource fixtures from within our API.

We have been experimenting with ways around these limitations, but don't have anything readily available right now.

@saniales
Copy link

saniales commented Feb 10, 2022

to everybody still searching for a solution for unit tests without stripe mock

I managed to mock without it in the way I explained here on Stack Overflow

@guptaaashutosh
Copy link

guptaaashutosh commented Mar 15, 2024

@meggieveggie Thanks for the feedback. We usually recommend using stripe-mock for something like this which is what we use in our test suite. You can read more about this here: https://github.com/stripe/stripe-mock/ Would that work for you?

how it can be use in unit testing?. Can you refer any example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants