2

I'm building an automated test suite to integration/feature test my organization's Stripe implementation within a GitLab CI pipeline. We're running Laravel 8 and using phpunit for testing.

Within this suite I'm testing both happy and non-happy paths (i.e. I want to test valid and invalid payment details).

At the moment the suite is just running locally and is using a Stripe account that dedicated for testing using Stripe's test mode. I've been using Stripe's testing tokens to create different types of payments and its all working good so far. However, I want the test suite to run quickly within a CI pipeline, and I found stripe-mock as an alternative. stripe-mock claims it makes,

test suites integrating with Stripe faster and less brittle.

However, stripe-mock notes that a current limitation is,

Testing for specific responses and errors is currently not supported. It will return a success response instead of the desired error response.

So based on this I've got two questions:

  1. What is the use case of stripe-mock if it will always return a successful response regardless of the validity of the payment?
  2. Is there another preferred way integration testing a Stripe implementation, or is what I'm currently doing the best approach?

With regards to my second question I believe my options are to:

  1. Keep using Stripe's test mode.
  2. Build a happy-path suite using stripe-mock, and a non-happy-path suite using Stripe's test mode.
  3. Build a happy-path suite using stripe-mock, and just manual test non-happy paths. ( I don't really see this as a valid option for me as I would like smoke tests for all Stripe related functionality)
  4. Something else?

Thanks in advance!

2 Answers 2

0

For future folks who find this thread, here's an example of how to setup your Rails test environment and use stripe-ruby-mock to test the Stripe API without accessing the production instance:

https://betterprogramming.pub/test-driven-development-with-stripe-and-ruby-on-rails-cfc81e3e261

1
0

What is the use case of stripe-mock if it will always return a successful response regardless of the validity of the payment?

It reminds me of the time I pretended to mock up MongoDB. For the sake of the answer, I won't tell the story but believe me when I say I was too naive to believe it.

In my experience, I think stripe-mock can help you execute tests faster but not build confidence in your tests. You have to decide what your test should provide you with. If you ask me, confidence > velocity all the time.

That said, It doesn't mean I will give up on making test executions to be faster.

Is there another preferred way of integration testing a Stripe implementation, or is what I'm currently doing the best approach?

Sure. Implement a Proxy and cache requests and responses. It might interest you: Mountebank

How would I do it?

  • Run a Mountebank container enabling persistence to file

  • Enable the proxy mode "proxyOnce"

  • Tune up accurate predicateGenerators

  • Set up integration tests to send requests to Mountebank instead of Stripe

  • Execute Contract tests to record requests and Stripe responses.

    Note: Don't test the whole API, only those features you need

  • Save the Mountebank configuration to a file I can version.

  • Run all my tests

4th and 5th can be performed once in a while from a different pipeline (let's say daily overnight). The pipeline keeps stubs up-to-date and ensures the Mountebank server responds according to the current version of the Stripe API contract.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.