पाठ 24 / 25

Testing Strategy

Test cards, CLI triggers and test clocks.

Cover success, failure and time

In test mode no real money moves. Use documented test cards: 4242 4242 4242 4242 succeeds (any future expiry and any CVC), 4000 0000 0000 0002 is declined, 4000 0000 0000 9995 is declined for insufficient funds and 4000 0025 0000 3155 requires authentication; the testing docs list more, including ones that create disputes. Trigger webhook events with the Stripe CLI. For subscriptions, test clocks let you create a customer attached to a simulated clock and advance time, so you can watch trials end, renewals bill and failed payments move to past_due in minutes instead of months. Automate the key paths in integration tests against test mode, and unit-test your webhook handlers with recorded event payloads.

Simulating a month with a test clock

Server-side Node.js in test mode.

const now = Math.floor(Date.now() / 1000);
const clock = await stripe.testHelpers.testClocks.create({ frozen_time: now });

const customer = await stripe.customers.create({
  email: 'test@example.com',
  test_clock: clock.id,
});
// attach a test payment method and create a subscription for this customer...

// jump 31 days ahead: Stripe generates the renewal invoice and fires webhooks
await stripe.testHelpers.testClocks.advance(clock.id, {
  frozen_time: now + 31 * 24 * 60 * 60,
});

Never test with real cards in live mode

Real card numbers are not allowed in test mode, and testing in live mode with real cards risks fees, disputes and fraud flags. Use test mode and test cards.

त्वरित जाँच: What do test clocks let you do?

  • Change the API version
  • Speed up live payouts
  • Advance simulated time to test subscription billing quickly
  • Bypass 3D Secure in live mode
Answer

Advance simulated time to test subscription billing quickly — Trials, renewals and retries can be tested in minutes.