Testing Pipeline Code and the Data It Produces
This lesson explains how to test both the code that transforms data and the data that results, since a pipeline can run without errors and still produce wrong data.
Learning outcomes
After completing this lesson, you will be able to:
- Distinguish unit tests, local job runs and integration tests of pipeline code.
- Test the data with schema, row count and quality checks.
- Prepare safe, representative test data.
Testing the code
Pipeline code is tested at three levels, each catching different problems. Unit tests check individual transformation functions with pytest and small sample DataFrames, called fixtures. They run in seconds and catch logic errors early. Local job runs execute a complete Glue or Spark script with the Glue Docker image or a local Spark session, catching errors in how the pieces fit together without cloud costs. Integration tests run the pipeline against real services with test data in a test account, catching permission, configuration and service-behaviour problems before production. The following table summarises the levels.
| Level | What it tests | How |
|---|---|---|
| Unit tests | Individual transformation functions | pytest with small sample DataFrames (fixtures) |
| Local job runs | A complete Glue or Spark script | The Glue Docker image or a local Spark session |
| Integration tests | The pipeline against real services | A run on test data in a test account |
Which test level?
Testing the data
Code tests show that transformations behave as intended on sample inputs; data tests show that the actual outputs are correct and complete. Schema checks confirm that the output has the expected columns and types. Row counts are compared with the source, or with the output of the previous pipeline version, to detect lost or duplicated records.
Business rules check the meaning of the data, for example that amounts are never negative and keys are unique; AWS Glue Data Quality and the open-source Deequ library express such rules declaratively. Before a change to a pipeline is promoted, key metrics, such as total revenue per day, are compared between the old and new outputs, so that an unintended change in results is caught before consumers see it.
The following diagram shows the tests at each stage and a data check catching a lost half of the rows.

Data tests
Test data
Tests need representative data that is safe to use. Small, hand-made fixtures cover edge cases such as nulls, duplicates and malformed values. Larger samples of production data must have personal data masked or be generated synthetically, so that test environments do not hold sensitive data.
Testing a transformation before it reaches production
A data transformation should be tested at each stage of the delivery pipeline. The following table identifies the tests performed at each stage.
| Stage | Test |
|---|---|
| Every commit | Unit tests of transformation functions on small sample DataFrames (pytest) |
| Pull request | Lint SQL and Python; run Glue scripts locally in the Glue Docker image |
| Deploy to test | Run the pipeline on a sample of real data |
| Before promotion | Data quality checks: row counts, nulls, uniqueness compared with expectations |
| Production | Deploy through the pipeline with approval |
Testing data pipelines means testing the data as well as the code: a code change that passes unit tests can still drop half the rows. Comparing row counts and key metrics between the old and new outputs catches that before analysts do.
How can Glue scripts be tested before deployment?
Show answer
By running them locally in the Glue Docker image, using small fixture datasets.
Exam Tips
Remember for the exam
- Test transformations with small fixture datasets.
- Run Glue scripts locally in the Glue Docker image before deployment.
- Test the data as well as the code: row counts, schemas and business rules.
- Compare outputs of the old and new pipeline before promoting a change.
- Mask or synthesise personal data used in test environments.