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
Toggle test mode in the Dashboard
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.
Find your test API keys
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.
Use test card numbers
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.
1// Common test card numbers:2// Successful payment: 4242 4242 4242 42423// Declined card: 4000 0000 0000 00024// Requires authentication: 4000 0000 0000 32205// Insufficient funds: 4000 0000 0000 99956// Expired card: 4000 0000 0000 006978// 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.
Test webhooks locally
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.
1// Install Stripe CLI (macOS):2// brew install stripe/stripe-cli/stripe34// Log in:5// stripe login67// Forward webhooks to your local server:8// stripe listen --forward-to localhost:3000/webhooks/stripe910// Trigger a test event:11// stripe trigger payment_intent.succeededExpected result: Webhook events are forwarded to your local server. The Stripe CLI displays the event type and your server's response.
View test data separately
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
1// test-payment.js2// Quick script to verify your test mode setup34const Stripe = require('stripe');56// Use your TEST secret key — starts with sk_test_7const stripe = Stripe(process.env.STRIPE_SECRET_KEY);89async function testPayment() {10 try {11 // Create a test PaymentIntent12 const intent = await stripe.paymentIntents.create({13 amount: 2000, // $20.00 in cents14 currency: 'usd',15 payment_method: 'pm_card_visa', // built-in test payment method16 confirm: true,17 automatic_payment_methods: {18 enabled: true,19 allow_redirects: 'never'20 }21 });2223 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());2728 // Verify it appears in test mode29 const retrieved = await stripe.paymentIntents.retrieve(intent.id);30 console.log('Retrieved status:', retrieved.status);3132 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}4041testPayment();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.
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.
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.
Talk to an Expert
Our team has built 600+ apps. Get personalized help with your project.
Book a free consultation