

In Part 2 of our CI/CD series, we showed how to set up automated testing with make test-e2e—running a workflow with test data and checking that it produces results. If the script runs without crashing, it is tempting to conclude that everything works. The uncomfortable part is that a pipeline which runs successfully does not necessarily produce correct results.
This post looks at why testing goes beyond "run the code and check it does not crash," and at the kinds of tests that help catch bugs a simple end-to-end test would miss.
Consider a quality control pipeline (like the one from Part 2) that:
Does this mean everything is correct? Not necessarily. A few scenarios that occur in practice:
Scenario 1: silent parameter changes
# Your original scriptfastqc --qual-threshold 30 sample.fastq.gz -o result/
# A colleague modifies it (accidentally)fastqc --qual-threshold 10 sample.fastq.gz -o result/
# The pipeline still runs successfully!# But now you're accepting lower quality reads without realizing itScenario 2: data corruption
# Your QC output looks fine visually# But internally, MultiQC may have corrupted data:# - Missing sample names in reports# - Incorrect statistics calculations# - Incomplete HTML output
# A simple "did it run?" test won't catch thisScenario 3: edge-case failures
# Your pipeline works with 100 samples# But when you try with 1,000 samples:# - Memory usage explodes# - Temporary file naming conflicts# - Processes timeout unexpectedlyThese are not hypothetical—they are the kinds of bugs that appear in real bioinformatics projects. The lesson is that tests need to go beyond execution alone.
Instead of one monolithic end-to-end test, it helps to think of testing in layers:
┌────────────────────────────────────────────────┐│ Layer 4: End-to-End Tests ││ "Does the full pipeline work with real data?" │├────────────────────────────────────────────────┤│ Layer 3: Integration Tests ││ "Do components work together correctly?" │├────────────────────────────────────────────────┤│ Layer 2: Contract Tests (Output Validation) ││ "Are the results in the expected format?" │├────────────────────────────────────────────────┤│ Layer 1: Unit Tests (Individual Functions) ││ "Does this logic work correctly?" │└────────────────────────────────────────────────┘Let us look at each layer with concrete examples.
These test small, isolated pieces of code—usually Python functions that parse or validate data.
Example: validating QC metrics
A validator that reads quality control metrics from a JSON file may accept bad data without complaint:
def parse_fastqc_json(json_file): """Parse FastQC JSON output.""" with open(json_file) as f: data = json.load(f)
# BUG: What if 'summary' key is missing? Crashes silently q30_rate = data['summary']['q30_rate']
# BUG: What if q30_rate is 0? No error checking return q30_rateUnit tests catch these bugs early:
def test_parse_fastqc_missing_summary(): """Should handle missing summary section.""" invalid_json = '{"other": "data"}'
with pytest.raises(KeyError): parse_fastqc_json(invalid_json)
def test_parse_fastqc_zero_rate(): """Should handle zero quality rate.""" result = parse_fastqc_json('{"summary": {"q30_rate": 0}}') assert result == 0 # Not False or None—explicitly 0These verify that tools produce output in the expected format. A pipeline might run without errors but still produce corrupted output.
Example: validating BAM file structure
# Layer 2 test: Is the BAM file valid?test_validate_bam_output() { # Run samtools sort samtools sort -o sorted.bam input.bam
# Check: Does the output file exist? test -f sorted.bam || exit 1
# Check: Is it actually a valid BAM file? samtools view -H sorted.bam > /dev/null || exit 1
# Check: Does it have the expected number of reads? read_count=$(samtools view -c sorted.bam) test $read_count -gt 0 || exit 1}This matters because MultiQC might run successfully on a corrupted BAM while the downstream analysis fails silently.
These verify that multiple components work together—for example, testing an entire subworkflow (QC → trimming → alignment).
# Layer 3 test: Do all steps work together?test_full_qc_trimming_workflow() { # Download test data make data
# Run: FastQC → Trimming → FastQC again bash workflow.sh data/sample_1.fastq.gz data/sample_2.fastq.gz result/
# Validate: All expected outputs exist test -f result/trimming_report.html test -f result/trimmed_1.fastq.gz test -f result/trimmed_2.fastq.gz
# Validate: Output files are non-empty test -s result/trimmed_1.fastq.gz test -s result/trimmed_2.fastq.gz}The make test-e2e test from Part 2 is a Layer 4 test. It is useful, but not sufficient on its own.
The following are bugs that Layer 4 (end-to-end) tests would miss but other layers would catch.
# Original scriptfastqc --qual-threshold 30 input.fastq.gz
# Developer accidentally changes itfastqc --qual-threshold 5 input.fastq.gzLayer 4 test (end-to-end):
Layer 2 test (contract):
# Contract test for quality thresholdsq_threshold=$(grep "Passed filters:" result.html | grep -oP '\d+')test $q_threshold -ge 20 || (echo "Quality threshold too low"; exit 1)# Trimming tool runs successfully, but outputs wrong number of reads
original_reads=$(samtools view -c input.bam)trimmed_reads=$(samtools view -c trimmed.bam)
# Bug: trimmed_reads should be LESS than original_reads# If trimmed_reads > original_reads, something is wrong!Layer 4 test (end-to-end):
Layer 3 test (integration):
# Integration test: Validate trimming removes readstest $original_reads -gt $trimmed_reads || \ (echo "ERROR: Trimming removed no reads"; exit 1)# Your script doesn't check if input existsfastqc $input_file # What if $input_file doesn't exist?Layer 4 test (end-to-end):
Layer 1 test (unit):
def test_fastqc_missing_input(): """Should fail gracefully with missing input.""" with pytest.raises(FileNotFoundError): run_fastqc("nonexistent.fastq.gz")As described in Part 2, the Makefile originally had:
test-e2e: data/GSE110004 ${HOME}/.pixi/bin/pixi run bash main.sh ...Validation layers can be added alongside it:
# Layer 1: Unit tests (validate Python parsing functions)test-unit: pytest tests/unit/ -v
# Layer 2: Contract tests (validate output formats)test-contract: data/GSE110004 bash tests/contract/validate_fastqc_output.sh result/
# Layer 3: Integration tests (validate multi-step workflows)test-integration: data/GSE110004 bash tests/integration/test_qc_pipeline.sh
# Layer 4: End-to-end test (run full pipeline)test-e2e: data/GSE110004 ${HOME}/.pixi/bin/pixi run bash main.sh data/GSE110004/*_1.fastq.gz data/GSE110004/*_2.fastq.gz result
# Run all teststest-all: test-unit test-contract test-integration test-e2e @echo "All tests passed!"#!/bin/bash
RESULT_DIR=$1
echo "Validating FastQC outputs..."
# Check 1: HTML reports existtest -f "$RESULT_DIR"/*.html || { echo "ERROR: No FastQC HTML reports found" exit 1}
# Check 2: Check required sections exist in HTMLfor html_file in "$RESULT_DIR"/*.html; do # FastQC must have these sections grep -q "Per base sequence quality" "$html_file" || { echo "ERROR: Missing quality metrics in $html_file" exit 1 } grep -q "Per base sequence content" "$html_file" || { echo "ERROR: Missing content metrics in $html_file" exit 1 }done
# Check 3: MultiQC report exists and has contenttest -s "$RESULT_DIR/multiqc_report.html" || { echo "ERROR: MultiQC report is empty or missing" exit 1}
# Check 4: MultiQC HTML contains sample namesgrep -q "General Statistics" "$RESULT_DIR/multiqc_report.html" || { echo "ERROR: MultiQC missing summary statistics" exit 1}
echo "✓ All contract tests passed!"#!/bin/bash
echo "Testing QC → Trimming → QC pipeline..."
# Step 1: Run first FastQCfastqc input.fastq.gz -o tmp_qc1/count1=$(samtools view -c tmp_qc1/input_fastqc.zip)
# Step 2: Run trimmingtrimmomatic SE input.fastq.gz trimmed.fastq.gz LEADING:3 TRAILING:3
# Step 3: Run second FastQCfastqc trimmed.fastq.gz -o tmp_qc2/count2=$(samtools view -c tmp_qc2/trimmed_fastqc.zip)
# Integration check: Second QC should show improvement# (This is a behavior test: does trimming actually improve quality?)if [ "$count2" -lt "$count1" ]; then echo "✓ Integration test passed: Quality improved after trimming"else echo "ERROR: Trimming did not improve quality metrics" exit 1fi
rm -rf tmp_qc1 tmp_qc2For Nextflow pipelines, testing is similar but uses the nf-test framework:
# Layer 2: Contract test for a Nextflow processtest("samtools sort produces valid BAM") { when { input[0] = [ [id: 'test'], file('test.bam') ] }
then { assert process.success
// Layer 2: Validate BAM structure def bam_file = process.out.bam[0][1] assert shell("samtools view -H ${bam_file}").exitStatus == 0 }} ▲ ╱ ╲ ╱ ╲ Layer 4: End-to-End (5%) ╱ E2E ╲ "Did the pipeline finish?" ╱───────╲ ╱ ╲ ╱Integration╲ Layer 3 (15%) ╱ (Contract) ╲ "Do outputs have correct format?" ╱───────────────╲ ╱ ╲ ╱ Unit Tests ╲ Layer 2 + 1 (80%) ╱ (Validation) ╲ "Does this logic work? Handle errors?" ╱───────────────────────╲
Each layer catches different types of bugs that the layer above might miss.Key insight: a pipeline that "runs successfully" (Layer 4 ✓) might still have:
Starting simple:
Add Layer 1 (unit tests):
pytest tests/unit/ --cov # If you have Python codeAdd Layer 2 (contract tests):
bash tests/contract/*.sh # Validate outputsKeep your Layer 4 (end-to-end):
make test-e2e # From Part 2Run them all before pushing:
make test-all




