# How to enable test mode in Stripe

- Tool: Stripe
- Difficulty: Beginner
- Time required: 5 minutes
- Compatibility: All Stripe accounts, all API versions
- Last updated: March 2026

## 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.

## Before you start

- 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.

```
// Common test card numbers:
// Successful payment:     4242 4242 4242 4242
// Declined card:           4000 0000 0000 0002
// Requires authentication: 4000 0000 0000 3220
// Insufficient funds:      4000 0000 0000 9995
// Expired card:            4000 0000 0000 0069

// Expiry: any future date (e.g., 12/34)
// CVC: any 3 digits (e.g., 123)
// 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.

```
// Install Stripe CLI (macOS):
// brew install stripe/stripe-cli/stripe

// Log in:
// stripe login

// Forward webhooks to your local server:
// stripe listen --forward-to localhost:3000/webhooks/stripe

// Trigger a test event:
// 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 code example

File: `test-payment.js`

```javascript
// test-payment.js
// Quick script to verify your test mode setup

const Stripe = require('stripe');

// Use your TEST secret key — starts with sk_test_
const stripe = Stripe(process.env.STRIPE_SECRET_KEY);

async function testPayment() {
  try {
    // Create a test PaymentIntent
    const intent = await stripe.paymentIntents.create({
      amount: 2000,        // $20.00 in cents
      currency: 'usd',
      payment_method: 'pm_card_visa',  // built-in test payment method
      confirm: true,
      automatic_payment_methods: {
        enabled: true,
        allow_redirects: 'never'
      }
    });

    console.log('Payment succeeded!');
    console.log('PaymentIntent ID:', intent.id);
    console.log('Status:', intent.status);
    console.log('Amount:', intent.amount / 100, intent.currency.toUpperCase());

    // Verify it appears in test mode
    const retrieved = await stripe.paymentIntents.retrieve(intent.id);
    console.log('Retrieved status:', retrieved.status);

    return intent;
  } catch (err) {
    console.error('Test failed:', err.message);
    if (err.type === 'StripeAuthenticationError') {
      console.error('Check that STRIPE_SECRET_KEY starts with sk_test_');
    }
  }
}

testPayment();
```

## Common mistakes

- **Using live API keys (sk_live_, pk_live_) during development** — undefined Fix: Always use test keys (sk_test_, pk_test_) during development. Check the key prefix before running your code.
- **Using test card numbers in live mode** — undefined Fix: Test card numbers like 4242424242424242 only work in test mode. In live mode, they will be declined.
- **Forgetting to switch back to live mode before deploying** — undefined Fix: Replace all test keys with live keys in your production environment. Use environment variables to manage this cleanly.
- **Testing webhooks without the Stripe CLI** — undefined Fix: 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

## 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.

---

Source: https://www.rapidevelopers.com/stripe-guide/how-to-enable-test-mode-in-stripe
© RapidDev — https://www.rapidevelopers.com/stripe-guide/how-to-enable-test-mode-in-stripe
