ETL/DWH Testing: Data Warehouse Testing Concepts Explained with SQL

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.

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

SQL
-- 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):

  1. Requirement and mapping review: read the business requirements and the source-to-target mapping document (STM). Every transformation rule you test comes from here.
  2. Test planning: decide scope (which tables, which loads: full or incremental), environments, test data and entry/exit criteria.
  3. Test case design: write checks for metadata, completeness, data mismatch, transformations, duplicates and SCD behaviour.
  4. Test data and environment setup: prepare source data that covers edge cases such as nulls, late-arriving rows and changed dimension values.
  5. Execution: run the ETL job, then run your SQL checks against source, staging and target.
  6. Defect logging and retest: log mismatches with the failing query and sample rows, then retest after the fix.
  7. 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

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

SQL
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

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

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

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

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

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

FieldExample
Test IDDWH_TC_001
ObjectiveValidate row count — source matches target
Pre-conditionETL job for the test date has completed
Test StepsRun COUNT(*) on source and target for the same date filter
Expected ResultSource count = Target count
Actual Result(fill after execution)
StatusPASS / 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:

  1. Read the mapping document and data model. List every target table, its source, its grain and its business key.
  2. Check metadata first. Table and column names, data types, lengths and constraints against the design.
  3. Test dimensions before facts. Facts depend on dimension keys, so start with uniqueness, SCD history and default "unknown" rows in dimensions.
  4. Reconcile facts with the source. Counts by date, source-minus-target, transformation recalculation and sums of measures.
  5. Check referential integrity. Every fact foreign key must find its dimension row.
  6. Test incremental loads and reruns. Load day 2 on top of day 1; rerun a batch and confirm no duplicates.
  7. Validate reports last. Recalculate a few dashboard numbers from the warehouse with SQL.
  8. 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

ToolTypeBest For
SQLManualAll validation queries — universal
Python + pandasScriptedLarge-scale automated comparisons
Great ExpectationsOpen-sourceProduction data quality monitoring
QuerySurgeCommercialAutomated ETL regression testing
dbt testsBuilt-inTeams 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.
Learn DWH testing with hands-on practice
The ETL Testing Course includes complete data warehouse testing modules with real SQL validation scenarios, test case design, and tools coverage.

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?
DWH testing (data warehouse testing) validates that data stored in a DWH is accurate, complete, and consistent. It covers ETL pipeline validation, schema testing, data quality checks, performance testing, and regression testing after ETL changes.
What SQL queries are most important in data warehouse testing?
The most critical patterns are: row count reconciliation (COUNT(*) comparison), EXCEPT/MINUS queries for missing records, GROUP BY HAVING COUNT > 1 for duplicates, LEFT JOIN WHERE IS NULL for referential integrity, and transformation validation queries that apply business rules to source data.
What are the key data warehouse testing concepts?
Source-to-target mapping, staging/core/mart layers, fact and dimension tables, surrogate vs business keys, slowly changing dimensions (SCD), grain and incremental vs full loads. Every ETL/DWH test case traces back to one of these.
What is the data warehouse testing life cycle?
The DWH testing life cycle has seven phases: requirement and mapping review, test planning, test case design, test data and environment setup, execution, defect logging and retest, and regression and sign-off. See the life cycle section above.
What tools are used for data warehouse testing?
Common tools include SQL (universal), Python with pandas for automated comparisons, Great Expectations for production data quality monitoring, QuerySurge for automated ETL regression testing, and dbt tests for teams using dbt for transformations.

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
Written by

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.

4.5 Rating 913+ Students Google Partner 79 Lectures

Master Data Warehouse Testing

The ETL Testing Course covers complete DWH testing with real SQL validation scenarios, test case design, and data quality tools.

Preview Free Lectures on Udemy