Your data warehouse is the single source of truth for the entire organization — financial reports, executive dashboards, and machine learning models all depend on it. When the data inside is wrong, everything downstream is wrong too — silently. Data warehouse testing — often shortened to DWH testing — is how you prevent that. This guide covers data warehouse ETL testing end to end, with SQL you can run today.
What is DWH Testing?
DWH testing (data warehouse testing) validates that:
- Data was loaded correctly from all source systems
- Transformation logic was applied accurately (business rules, calculations, lookups)
- Data is complete — no records lost, no duplicates created
- The schema is correct — right tables, columns, data types, and relationships
- Query performance meets SLA requirements
Data Warehouse Testing Concepts
ETL/DWH testing rests on a handful of data warehouse concepts. Know these and every test case makes sense:
- Source-to-target mapping: the document that says where each target column comes from and which rule transforms it. Every test traces back to it.
- Staging, core and mart layers: data lands raw in staging, is cleaned and integrated in the core warehouse, then shaped for reports in data marts. Test each hop.
- Fact and dimension tables: facts hold measures (amount, quantity); dimensions hold context (customer, product, date). See fact and dimension tables.
- Surrogate vs business keys: the warehouse generates surrogate keys; tests check that every business key maps to exactly one current surrogate key.
- Slowly changing dimensions (SCD): Type 1 overwrites, Type 2 keeps history with effective dates and a current flag. See SCD testing.
- Grain: what one fact row represents (one order line, one day per store). Duplicate tests depend on the grain.
- Incremental vs full loads: incremental loads must pick up only new and changed rows without duplicates.
More theory with examples: data warehouse concepts. Want to automate these checks? Compare data warehouse automation testing tools.
The 5 Types of DWH Tests
1. ETL / Pipeline Testing
Validates data movement from source → staging → target. Key checks: row count reconciliation, transformation accuracy, null handling, duplicate detection, and rejection record capture.
2. Schema Testing
Validates the physical structure of warehouse tables.
-- Verify column data types (SQL Server / PostgreSQL) SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'fact_sales' ORDER BY ORDINAL_POSITION;
3. Data Quality Testing
Validates the content of the data itself — nulls, duplicates, out-of-range values.
-- Null check on mandatory columns SELECT COUNT(*) AS null_count FROM fact_sales WHERE order_id IS NULL OR customer_id IS NULL; -- Duplicate check SELECT order_id, COUNT(*) AS cnt FROM fact_sales GROUP BY order_id HAVING COUNT(*) > 1; -- Value range check SELECT * FROM fact_sales WHERE quantity < 0 OR price < 0;
4. Performance Testing
Validates that ETL jobs complete within SLA and key queries return within acceptable time. Use ETL monitoring dashboards and SQL execution plans (EXPLAIN ANALYZE in PostgreSQL).
5. Regression Testing
After any ETL change or deployment, re-run all critical tests to confirm existing data was not broken. This is where a maintained test case library pays off.
Data Warehouse Testing Life Cycle
DWH testing follows a predictable life cycle. Each phase produces something the next phase depends on (full walkthrough: ETL testing process):
- Requirement and mapping review: read the business requirements and the source-to-target mapping document (STM). Every transformation rule you test comes from here.
- Test planning: decide scope (which tables, which loads: full or incremental), environments, test data and entry/exit criteria.
- Test case design: write checks for metadata, completeness, data mismatch, transformations, duplicates and SCD behaviour.
- Test data and environment setup: prepare source data that covers edge cases such as nulls, late-arriving rows and changed dimension values.
- Execution: run the ETL job, then run your SQL checks against source, staging and target.
- Defect logging and retest: log mismatches with the failing query and sample rows, then retest after the fix.
- Regression and sign-off: re-run the full suite and sign off when exit criteria are met.
Critical SQL Validation Patterns
Below are the seven patterns that matter most for DWH testing. For 15 copy-ready queries, see ETL testing SQL.
Pattern 1: Row Count Reconciliation
-- Source count SELECT COUNT(*) FROM source_db.orders WHERE created_date = CURRENT_DATE - 1; -- Target count (must match) SELECT COUNT(*) FROM dw.fact_orders WHERE etl_load_date = CURRENT_DATE - 1;
Pattern 2: Source-to-Target Comparison
SELECT order_id, customer_id, total_amount FROM source_db.orders EXCEPT SELECT order_id, customer_id, total_amount FROM dw.fact_orders; -- Returns records in source but missing/different in target
Pattern 3: Transformation Validation
-- Rule: final_price = unit_price * quantity * (1 - discount) SELECT order_id, ROUND(unit_price * quantity * (1 - discount), 2) AS expected, final_price AS actual FROM dw.fact_orders WHERE ABS(unit_price * quantity * (1 - discount) - final_price) > 0.01; -- Should return 0 rows
Pattern 4: SCD Type 2 Validation
All SCD Type 1, 2 and 3 scenarios are covered in SCD testing.
-- Only one active record per customer SELECT customer_id, COUNT(*) AS active_records FROM dim_customer WHERE is_active = 1 GROUP BY customer_id HAVING COUNT(*) > 1; -- Should return 0 rows
Pattern 5: Referential Integrity
-- Every order must have a valid customer in dim_customer SELECT f.order_id FROM fact_orders f LEFT JOIN dim_customer c ON f.customer_id = c.customer_id WHERE c.customer_id IS NULL; -- Should return 0 rows
Pattern 6: Metadata Check
Before checking any data, confirm the target table structure matches the mapping document: column names, data types, lengths and nullability. More in metadata testing in ETL.
-- Columns whose type or length differs between staging and target SELECT s.COLUMN_NAME, s.DATA_TYPE AS src_type, t.DATA_TYPE AS tgt_type, s.CHARACTER_MAXIMUM_LENGTH AS src_len, t.CHARACTER_MAXIMUM_LENGTH AS tgt_len FROM INFORMATION_SCHEMA.COLUMNS s JOIN INFORMATION_SCHEMA.COLUMNS t ON t.COLUMN_NAME = s.COLUMN_NAME AND t.TABLE_NAME = 'dim_customer' WHERE s.TABLE_NAME = 'stg_customer' AND (s.DATA_TYPE <> t.DATA_TYPE OR s.CHARACTER_MAXIMUM_LENGTH <> t.CHARACTER_MAXIMUM_LENGTH); -- Should return 0 rows (unless the mapping says otherwise)
Pattern 7: Column Data Profiling
Profiling compares the shape of a column in source and target. If counts match but the profile does not, rows were changed or truncated along the way. See data profiling in ETL testing.
-- Run on source and target, then compare the two result rows SELECT COUNT(*) AS total_rows, COUNT(DISTINCT customer_id) AS distinct_ids, SUM(CASE WHEN email IS NULL THEN 1 ELSE 0 END) AS null_emails, MIN(signup_date) AS min_date, MAX(signup_date) AS max_date, MAX(LENGTH(full_name)) AS max_name_len FROM dw.dim_customer;
Test Case Template
| Field | Example |
|---|---|
| Test ID | DWH_TC_001 |
| Objective | Validate row count — source matches target |
| Pre-condition | ETL job for the test date has completed |
| Test Steps | Run COUNT(*) on source and target for the same date filter |
| Expected Result | Source count = Target count |
| Actual Result | (fill after execution) |
| Status | PASS / FAIL |
Testing a Data Warehouse Step by Step
When you join a project and are asked to start testing the data warehouse, this order works on almost every project:
- Read the mapping document and data model. List every target table, its source, its grain and its business key.
- Check metadata first. Table and column names, data types, lengths and constraints against the design.
- Test dimensions before facts. Facts depend on dimension keys, so start with uniqueness, SCD history and default "unknown" rows in dimensions.
- Reconcile facts with the source. Counts by date, source-minus-target, transformation recalculation and sums of measures.
- Check referential integrity. Every fact foreign key must find its dimension row.
- Test incremental loads and reruns. Load day 2 on top of day 1; rerun a batch and confirm no duplicates.
- Validate reports last. Recalculate a few dashboard numbers from the warehouse with SQL.
- Save every query as a regression test and automate it for the next release.
Following this order means defects are found in the layer that caused them, instead of surfacing as a confusing report mismatch later. Keep a simple tracker with one row per table and a column per step, so the team can see at a glance how far testing of the data warehouse has progressed and which tables are blocked.
Tools for DWH Testing
| Tool | Type | Best For |
|---|---|---|
| SQL | Manual | All validation queries — universal |
| Python + pandas | Scripted | Large-scale automated comparisons |
| Great Expectations | Open-source | Production data quality monitoring |
| QuerySurge | Commercial | Automated ETL regression testing |
| dbt tests | Built-in | Teams using dbt for transformations |
Where Most Teams Go Wrong
- Testing only on day one. Data quality degrades over time as source systems change. Run your test suite after every ETL cycle.
- Skipping regression tests. An ETL fix for one table often silently breaks another. Always run the full suite after changes.
- Only checking counts. A matching row count does not mean the data is correct. Always validate transformation logic and data quality separately.
Ready-made checks: see 35 ETL testing test cases with examples covering completeness, transformations, data quality, SCD and incremental loads.
ETL testing tool tutorials: ETL testing SQL queries · QuerySurge ETL testing · Informatica ETL testing · ETL testing tools · ETL automation testing · Python ETL testing framework · dbt testing tutorial · Great Expectations tutorial
Data warehouse basics: SCD types · data warehouse concepts · star vs snowflake schema · fact and dimension tables · data reconciliation · data warehouse interview questions · ETL concepts
Frequently Asked Questions
What is DWH testing?
What SQL queries are most important in data warehouse testing?
What are the key data warehouse testing concepts?
What is the data warehouse testing life cycle?
What tools are used for data warehouse testing?
How do you start testing a data warehouse?
Start with the mapping document and data model, then check metadata, test dimensions before facts, reconcile facts with the source, check referential integrity, test incremental loads and reruns, and validate reports last. Save every query as a regression test.
Asim Noaman Lodhi
Certified Google Partner · QA Consultant · 12+ Years IT
QA consultant specializing in ETL testing and data quality. Trained 913+ students to transition into data testing roles through hands-on, real-world instruction.