Skip to main content
RapidDev - Software Development Agency
retool-tutorial

How to Use Retool's Testing Environment

Retool has two environments: staging (for testing) and production (for live users). Configure resources with staging/production variants using Retool Environments (Settings → Environments). In staging, queries use staging database credentials. Test changes in the editor's Preview mode before deploying. Use {{ retoolContext.environment === 'staging' }} to show debug info only in staging.

What you'll learn

  • Understand the difference between Retool's staging environment, preview mode, and production
  • Configure staging and production resources so queries switch data sources based on environment
  • Use Preview mode to test app changes without publishing them to live users
  • Use {{ retoolContext.environment }} to conditionally show debug info in staging only
  • Create a QA checklist before deploying major Retool app changes
Book a free consultation
4.9Clutch rating
600+Happy partners
17+Countries served
190+Team members
Advanced7 min read25-30 minRetool Cloud and Self-hosted (Environments feature on Business+)Last updated March 2026RapidDev Engineering Team
TL;DR

Retool has two environments: staging (for testing) and production (for live users). Configure resources with staging/production variants using Retool Environments (Settings → Environments). In staging, queries use staging database credentials. Test changes in the editor's Preview mode before deploying. Use {{ retoolContext.environment === 'staging' }} to show debug info only in staging.

Quick facts about this guide
FactValue
ToolRetool
DifficultyAdvanced
Time required25-30 min
CompatibilityRetool Cloud and Self-hosted (Environments feature on Business+)
Last updatedMarch 2026

Testing Strategies for Retool Apps Before Production Release

Retool apps connect directly to production databases by default. Without a testing strategy, any mistake in a query can affect production data — a wrong UPDATE query can corrupt real customer records. Testing environments prevent this.

Retool provides two mechanisms: (1) Preview mode — view your app changes before deploying to live users, using the same resources as production but in the editor context. (2) Retool Environments — configure multiple resource variants (staging, production) and switch between them, so staging apps connect to staging databases.

This tutorial covers both mechanisms and provides a practical QA workflow for testing before release.

Prerequisites

  • A Retool app connected to at least one database or API resource
  • A staging database or API endpoint to use for safe testing
  • Retool Business plan or higher for Environments feature

Step-by-step guide

1

Use Preview mode for quick pre-deployment testing

Before publishing changes, use Retool's Preview mode to test how your app looks and behaves without affecting live users. In the editor, click the eye icon or 'Preview' button (top-right) to switch from edit mode to preview mode. Preview mode simulates the app as it appears to end users — event handlers fire, queries run, and navigation works. Test your changes thoroughly in preview before clicking Deploy. Important: preview mode uses the same resources (database connections) as production — be careful with write operations.

Expected result: App changes tested in preview mode without affecting the deployed version visible to live users.

2

Configure staging and production environments

Navigate to Settings → Environments (Business+ feature). Create a 'Staging' environment alongside the existing 'Production' environment. For each database resource, configure environment-specific connection details: staging environment uses your staging database credentials, production environment uses your production credentials. The resource name stays the same — only the connection details differ per environment. This means the same app and queries work in both environments with no code changes.

Expected result: Staging environment configured with staging database credentials. Queries automatically use staging data when the staging environment is active.

3

Test with the staging environment active

In the Retool editor, find the environment switcher (usually in the top bar or app settings). Switch to 'Staging'. Now all queries that use resources configured with environment variants will connect to your staging database instead of production. Run your tests: submit forms, trigger queries, verify data operations. Any mistakes (wrong SQL, accidental deletes) only affect staging data, not production.

typescript
1// In JS Queries, check which environment is active:
2console.log('Current environment:', retoolContext.environment);
3// Returns: 'staging' or 'production'
4
5// Conditional behavior based on environment:
6if (retoolContext.environment === 'staging') {
7 // Extra debug logging in staging only
8 console.log('Query params:', JSON.stringify(queryParams));
9 console.log('Expected result:', JSON.stringify(updateQuery.data));
10}
11
12// Show staging banner to editors:
13// Text component value:
14{{ retoolContext.environment === 'staging' ? '⚠️ STAGING — Not production data' : '' }}

Expected result: Tests run against staging data. Production data is protected from test-related changes.

4

Use retoolContext.environment for conditional debug features

Add a staging-only debug banner at the top of your app using {{ retoolContext.environment }} to remind users they're in a test environment. Also use this to enable extra debug logging in JS Queries that is disabled in production. This pattern prevents debug code from running in production while still being testable.

typescript
1// Staging banner component:
2// Add a Container at the top of the app
3// Hidden property: {{ retoolContext.environment !== 'staging' }}
4// Background color: #fef3c7 (yellow)
5// Content: ⚠️ STAGING ENVIRONMENT — Database changes will NOT affect production
6
7// Conditional debug logging in JS Query:
8if (retoolContext.environment === 'staging') {
9 console.log('[DEBUG] saveRecord params:', {
10 id: table1.selectedRow.data.id,
11 values: {
12 name: nameInput.value,
13 status: statusSelect.value,
14 },
15 });
16}

Expected result: Staging banner visible only in staging environment. Debug logging enabled only in staging.

5

Create a QA checklist for pre-deployment testing

Before deploying any significant change, run through a structured QA checklist. Build this checklist based on your app's critical functionality. Typical checklist items: load test data displays correctly, key user workflows complete without errors, error states display appropriate messages, permission restrictions work for each user group, mobile responsiveness (if applicable), and no console errors in DevTools.

typescript
1// QA CHECKLIST TEMPLATE
2// Run before every production deployment
3
4/*
5FUNCTIONALITY:
6[ ] Page loads without JavaScript errors (check DevTools Console)
7[ ] All queries return expected data (check Debug Panel Queries tab)
8[ ] Search/filter functionality works
9[ ] Sort functionality works
10[ ] Pagination works (if applicable)
11
12WRITE OPERATIONS:
13[ ] Form submission creates/updates record correctly
14[ ] Required field validation shows appropriate errors
15[ ] Success notification appears after save
16[ ] Data refreshes after save (table/list updates)
17[ ] Delete confirmation appears before destructive actions
18
19PERMISSIONS:
20[ ] Admin-only features hidden for non-admin users
21[ ] Test with a non-admin test account
22
23EDGE CASES:
24[ ] Empty table state shows appropriate message
25[ ] Error state (disconnect resource temporarily) shows user-friendly message
26[ ] Large dataset loads without performance issues
27*/

Expected result: All QA checklist items pass in staging environment before deploying to production.

Complete working example

JS Query: environmentAwareLogger
1// JS Query: environmentAwareLogger
2// Utility for environment-aware logging and debugging
3// Include this in JS Queries where detailed debug logging is needed
4
5const IS_STAGING = retoolContext.environment === 'staging';
6
7// Log only in staging
8const debugLog = (label, data) => {
9 if (IS_STAGING) {
10 console.log(`[STAGING DEBUG] ${label}:`, JSON.stringify(data, null, 2));
11 }
12};
13
14// Assertion that throws in staging, silent in production
15const assert = (condition, message) => {
16 if (!condition && IS_STAGING) {
17 console.error(`[STAGING ASSERTION FAILED] ${message}`);
18 utils.showNotification({
19 title: 'Staging assertion failed',
20 description: message,
21 notificationType: 'error',
22 });
23 }
24};
25
26// Example usage in a save operation:
27debugLog('Table selected row', table1.selectedRow.data);
28debugLog('Form values', {
29 title: titleInput.value,
30 status: statusSelect.value,
31});
32
33assert(titleInput.value, 'Title should not be empty before save');
34assert(table1.selectedRow.data.id, 'A row must be selected before save');
35
36// ... rest of save logic
37await updateRecord.trigger();
38
39debugLog('Update result', updateRecord.data);
40assert(updateRecord.data.length > 0, 'Update should affect at least 1 row');

Common mistakes

Why it's a problem: Using Preview mode to test write operations (INSERT/UPDATE/DELETE) assuming they don't affect production

How to avoid: Preview mode uses the same resource connections as production. Write queries in preview mode execute against your real database. Use staging environment (with staging resource configuration) for testing writes safely.

Why it's a problem: Not testing with non-admin permissions before deploying

How to avoid: Admin users bypass many permission restrictions. Always test as a non-admin user to verify that permission-gated features work correctly. Create a dedicated test account in a non-admin group for this purpose.

Why it's a problem: Leaving retoolContext.environment conditional code out of cleanup, deploying debug logging to production

How to avoid: Always use {{ retoolContext.environment === 'staging' }} conditions to gate debug code. Review all console.log statements before deploying — use the environment check to ensure they only run in staging.

Best practices

  • Always have a staging environment with real-ish (anonymized) data that mirrors production structure
  • Test with a non-admin test account before deploying — admin access can mask permission-related bugs
  • Never use production data for testing write operations — always test against staging data
  • Run the QA checklist from a fresh browser session (incognito) to test without cached state
  • Schedule deployments during low-traffic periods to minimize impact if a rollback is needed

Still stuck?

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

ChatGPT Prompt

I'm setting up a testing workflow for my Retool app. I need: (1) instructions for configuring Retool Environments with staging and production resource variants, (2) how to use Preview mode safely without accidentally modifying production data, (3) a JS Query that uses retoolContext.environment to enable extra debug logging only in staging, (4) a staging-only banner component that warns users they're not in production. Also explain the difference between Preview mode (same data, pre-deployment) and Environments (separate databases).

Retool Prompt

Configure Retool testing workflow: Settings → Environments → create 'Staging' environment, configure database resource with staging credentials. In app editor: environment switcher to toggle Staging/Production. Add staging banner: Container Hidden={{ retoolContext.environment !== 'staging' }}, yellow background. JS Query conditional logging: if (retoolContext.environment === 'staging') { console.log('[STAGING]', data); }. Show retoolContext.environment in a Text component.

Frequently asked questions

Is Retool Preview mode the same as a staging environment?

No — Preview mode shows your unpublished app changes before deploying, but still uses your production resources. A staging environment uses separate resource connections (pointing to a staging database), so write operations in staging don't affect production data. Use Preview mode for UI/layout testing and staging environment for testing write operations safely.

Can regular users (non-admins) access the staging environment in Retool?

Environments are an editor/admin feature — only users with edit access can switch environments. End users who access published apps always see the production environment. The staging environment is exclusively for development and testing purposes by your Retool editing team.

What if I don't have a staging database? Can I still test safely?

Without a staging database, use read-only testing strategies: test read queries freely, but for write operations, use a 'test_' prefixed table in production, add a confirmation dialog that lets you review the SQL before executing, or temporarily add a WHERE 1=0 clause to write queries to make them no-ops during testing.

RapidDev

Talk to an Expert

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

Book a free consultation

Learning is great. Shipping is faster with help.

Our engineers have built 600+ apps on Retool and the tools around it. If your project needs to be live sooner than your learning curve allows — book a free consultation.

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.