0
0
Testing Fundamentalstesting~10 mins

Pipeline stages and test gates in Testing Fundamentals - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test simulates a software delivery pipeline with multiple stages and test gates. It verifies that the pipeline stops if a test gate fails, ensuring only quality code moves forward.

Test Code - PyTest
Testing Fundamentals
class Pipeline:
    def __init__(self):
        self.stages = []

    def add_stage(self, name, test_gate):
        self.stages.append({'name': name, 'test_gate': test_gate})

    def run(self):
        for stage in self.stages:
            print(f"Running stage: {stage['name']}")
            if not stage['test_gate']():
                print(f"Test gate failed at stage: {stage['name']}")
                return False
        return True

# Define test gates

def unit_tests():
    # Simulate unit tests passing
    return True

def integration_tests():
    # Simulate integration tests passing
    return True

def e2e_tests():
    # Simulate end-to-end tests failing
    return False

# Setup pipeline
pipeline = Pipeline()
pipeline.add_stage('Build', unit_tests)
pipeline.add_stage('Integration', integration_tests)
pipeline.add_stage('E2E', e2e_tests)

# Run pipeline
result = pipeline.run()
assert result == False, "Pipeline should fail due to E2E test gate failure"
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Initialize pipeline and add stages with test gatesPipeline has 3 stages: Build, Integration, E2E with respective test gates-PASS
2Run pipeline: execute 'Build' stage test gate (unit_tests)Unit tests simulated as passingunit_tests() returns TruePASS
3Run pipeline: execute 'Integration' stage test gate (integration_tests)Integration tests simulated as passingintegration_tests() returns TruePASS
4Run pipeline: execute 'E2E' stage test gate (e2e_tests)E2E tests simulated as failinge2e_tests() returns FalsePASS
5Pipeline stops due to failed E2E test gatePipeline run returns False indicating failureassert result == FalsePASS
Failure Scenario
Failing Condition: If a test gate returns False, pipeline should stop and return False
Execution Trace Quiz - 3 Questions
Test your understanding
What happens when the E2E test gate fails in the pipeline?
AThe pipeline retries the E2E tests automatically
BThe pipeline stops and returns failure
CThe pipeline ignores the failure and continues
DThe pipeline skips the E2E stage and finishes
Key Result
Use test gates in pipeline stages to automatically stop the process when quality checks fail, preventing faulty code from progressing.