TDD: Build a Password Validator
Advanced · Write the code · from Test-Driven Development: Write the Test First, Then the Code
From the lesson: Test-Driven Development: Write the Test First, Then the Code
Imagine you're drawing a picture. Most people sketch the outline first, then fill in the colors. You wouldn't start by painting random patches of blue and hope a sky appears.
Read the lessonUse TDD to build a validate_password function that returns a list of error messages. Rules: (1) must be at least 8 characters, (2) must contain at least one digit, (3) must contain at least one uppercase letter. Return an empty list if the password is valid. Write tests for: a valid password, a too-short password, one missing a digit, and one missing uppercase. Print each test result as PASS: <test_name>, then print Password validator complete!.
# Step 1: Write tests first
# Step 2: Build validate_password to pass them
# Step 3: Run and print results
More TDD exercises
- Your First TDD CycleIntermediate
- Predict the TDD ProcessIntermediate
- TDD Bug Fix: Reproduce Then FixAdvanced
- TDD Challenge: Build a Word CounterAdvanced