stripe-ios icon indicating copy to clipboard operation
stripe-ios copied to clipboard

[Feature] Stripe Testing Library

Open trevor-holliday-instacart opened this issue 2 years ago • 1 comments

Is your feature request related to a problem? Please describe.

Following SOLID design principles we don't directly reference the Stripe SDK, which enables us to perform unit testing in places where Stripe will actually perform work. However, there are still areas that remain untested where we have Stripe conform to our protocols.

Describe the solution you'd like

It would be excellent if Stripe provided a test library that would allow us to substitute the main STPApiClient.shared reference with a mock , example STPApiClient.test that performed 0 network requests.

This would enable enhanced Unit and UI testing.

Describe alternatives you've considered

This is the safest path as it prevents initializers that should remain internal from becoming public.

Additional context

N/A

Thanks for the suggestion, we'll take a look at making it easier to mock STPAPIClient!

For our own testing, we use OHHTTPStubs and SWHttpTrafficRecorder in our STPNetworkStubbingTestCase to mock requests. You can see an example implementation in STPPaymentHandlerTests. It's not exactly what you're looking for, but it would allow you to write tests that perform 0 network requests.

davidme-stripe avatar Apr 25 '22 16:04 davidme-stripe