Skip to main content
RapidDev - Software Development Agency
stripe-guide

How to enable test mode in Stripe

Switch to test mode in Stripe by toggling the 'Test mode' switch in the top-right corner of the Dashboard. Test mode gives you separate API keys (pk_test_ and sk_test_) and test card numbers like 4242424242424242 so you can build and test your integration without processing real payments or moving real money.

What you'll learn

  • How to toggle between test and live mode in the Stripe Dashboard
  • Where to find your test API keys
  • How to use test card numbers to simulate payments
  • How to view test data separately from live data
Book a free consultation
4.9Clutch rating
600+Happy partners
17+Countries served
190+Team members
Beginner5 min read5 minutesAll Stripe accounts, all API versionsMarch 2026RapidDev Engineering Team
TL;DR

Switch to test mode in Stripe by toggling the 'Test mode' switch in the top-right corner of the Dashboard. Test mode gives you separate API keys (pk_test_ and sk_test_) and test card numbers like 4242424242424242 so you can build and test your integration without processing real payments or moving real money.

Enabling and Using Test Mode in Stripe

Every Stripe account has a built-in test mode that mirrors your live environment without processing real money. Test mode uses separate API keys, separate data, and special test card numbers. You can create customers, process payments, trigger webhooks, and test your entire flow safely. Switching between test and live mode takes one click.

Prerequisites

  • A Stripe account (free to create at dashboard.stripe.com)
  • Access to the Stripe Dashboard

Step-by-step guide

1

Toggle test mode in the Dashboard

Log in to the Stripe Dashboard. In the top-right corner, you will see a toggle labeled 'Test mode'. Click it to switch to test mode. The Dashboard header turns orange to indicate you are in test mode.

Expected result: The Dashboard shows an orange banner and all data displayed is test data. The toggle reads 'Test mode' with the switch in the ON position.

2

Find your test API keys

Go to Developers → API keys while in test mode. You will see your test publishable key (starts with pk_test_) and test secret key (starts with sk_test_). Use these in your development environment.

Expected result: Your test publishable key and test secret key are visible on the API keys page.

3

Use test card numbers

Stripe provides special card numbers that simulate different scenarios in test mode. The most common is 4242424242424242 for a successful payment. Use any future expiry date and any 3-digit CVC.

typescript
1// Common test card numbers:
2// Successful payment: 4242 4242 4242 4242
3// Declined card: 4000 0000 0000 0002
4// Requires authentication: 4000 0000 0000 3220
5// Insufficient funds: 4000 0000 0000 9995
6// Expired card: 4000 0000 0000 0069
7
8// Expiry: any future date (e.g., 12/34)
9// CVC: any 3 digits (e.g., 123)
10// ZIP: any 5 digits (e.g., 10001)

Expected result: Test payments appear in the Dashboard under Payments in test mode. No real money is moved.

4

Test webhooks locally

Use the Stripe CLI to forward webhook events to your local server. Install the CLI, log in, and run the listen command. This lets you test webhook handling without deploying.

typescript
1// Install Stripe CLI (macOS):
2// brew install stripe/stripe-cli/stripe
3
4// Log in:
5// stripe login
6
7// Forward webhooks to your local server:
8// stripe listen --forward-to localhost:3000/webhooks/stripe
9
10// Trigger a test event:
11// stripe trigger payment_intent.succeeded

Expected result: Webhook events are forwarded to your local server. The Stripe CLI displays the event type and your server's response.

5

View test data separately

All data created in test mode is completely separate from live data. Customers, payments, subscriptions, and products created in test mode never affect your live account. You can delete all test data from the Developers page if needed.

Expected result: Test mode shows only test transactions. Switching back to live mode shows only real transactions.

Complete working example

test-payment.js
1// test-payment.js
2// Quick script to verify your test mode setup
3
4const Stripe = require('stripe');
5
6// Use your TEST secret key — starts with sk_test_
7const stripe = Stripe(process.env.STRIPE_SECRET_KEY);
8
9async function testPayment() {
10 try {
11 // Create a test PaymentIntent
12 const intent = await stripe.paymentIntents.create({
13 amount: 2000, // $20.00 in cents
14 currency: 'usd',
15 payment_method: 'pm_card_visa', // built-in test payment method
16 confirm: true,
17 automatic_payment_methods: {
18 enabled: true,
19 allow_redirects: 'never'
20 }
21 });
22
23 console.log('Payment succeeded!');
24 console.log('PaymentIntent ID:', intent.id);
25 console.log('Status:', intent.status);
26 console.log('Amount:', intent.amount / 100, intent.currency.toUpperCase());
27
28 // Verify it appears in test mode
29 const retrieved = await stripe.paymentIntents.retrieve(intent.id);
30 console.log('Retrieved status:', retrieved.status);
31
32 return intent;
33 } catch (err) {
34 console.error('Test failed:', err.message);
35 if (err.type === 'StripeAuthenticationError') {
36 console.error('Check that STRIPE_SECRET_KEY starts with sk_test_');
37 }
38 }
39}
40
41testPayment();

Common mistakes when enabling test mode in Stripe

Why it's a problem: Using live API keys (sk_live_, pk_live_) during development

How to avoid: Always use test keys (sk_test_, pk_test_) during development. Check the key prefix before running your code.

Why it's a problem: Using test card numbers in live mode

How to avoid: Test card numbers like 4242424242424242 only work in test mode. In live mode, they will be declined.

Why it's a problem: Forgetting to switch back to live mode before deploying

How to avoid: Replace all test keys with live keys in your production environment. Use environment variables to manage this cleanly.

Why it's a problem: Testing webhooks without the Stripe CLI

How to avoid: Use 'stripe listen --forward-to localhost:PORT/path' to receive test webhook events locally.

Best practices

  • Use environment variables for API keys so you can switch between test and live keys without changing code
  • Add a visual indicator in your app's UI when running against test mode to prevent confusion
  • Test all error scenarios using Stripe's special test card numbers — not just the success case
  • Use the Stripe CLI to test webhooks locally before deploying webhook endpoints
  • Create test customers and subscriptions to verify your full billing flow end-to-end
  • Periodically delete test data from the Developers page to keep your test Dashboard clean
  • Run automated tests against the Stripe test API in your CI/CD pipeline

Still stuck?

Copy one of these prompts to get a personalized, step-by-step explanation.

ChatGPT Prompt

Explain how to enable and use Stripe test mode. Show me where to find test API keys in the Dashboard, list the most useful test card numbers for simulating different payment outcomes, and show a Node.js script that creates a test PaymentIntent to verify my setup is working.

Stripe Prompt

Write a Node.js script that verifies my Stripe test mode setup by creating a PaymentIntent with the pm_card_visa test payment method, confirming it, and logging the result. Include error handling for incorrect API keys.

Frequently asked questions

Does test mode cost anything?

No. All activity in test mode is completely free. No fees are charged for test transactions, and no real money is moved.

Can I use test mode and live mode at the same time?

Yes. You can open two browser tabs — one in test mode and one in live mode. Your application can also run test and live environments simultaneously with different API keys.

Do test mode payments show up on my tax reports?

No. Test mode data is completely separate from live data. Test transactions never appear in tax reports, payouts, or financial statements.

Can I test webhooks in test mode?

Yes. Use the Stripe CLI with 'stripe listen' to forward test webhook events to your local server. You can also trigger specific events with 'stripe trigger event_name'.

How do I know if I am in test mode or live mode?

In test mode, the Dashboard has an orange banner at the top and the URL contains /test/. API keys start with pk_test_ and sk_test_ instead of pk_live_ and sk_live_.

Can I transfer test data to live mode?

No. Test mode and live mode are completely separate environments. You cannot migrate customers, subscriptions, or any other objects from test to live mode.

RapidDev

Talk to an Expert

Our team has built 600+ apps. Get personalized help with your project.

Book a free consultation

Need help with your project?

Our experts have built 600+ apps and can accelerate your development. Book a free consultation — no strings attached.

Book a free consultation

We put the rapid in RapidDev

Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We'll discuss your project and provide a custom quote at no cost.