Skip to main content

Command Palette

Search for a command to run...

πŸ§ͺ Testing Explained Like You're 5

Published
β€’2 min read
S

Building AI systems and writing about how they actually work. Master of AI @ University of Technology Sydney. Previously B.Tech CS with focus on IoT. I believe the best way to learn is to explain. That's why I'm documenting tech concepts with simple analogies (@sreekarreddy.com). AWS Certified β€’ Azure AI Certified β€’ Neo4j Professional β€’ Google Data Analytics When not coding: exploring Sydney, working on side projects, and teaching tech to anyone who'll listen.

Trying to break your code before users do

Day 64 of 149

πŸ‘‰ Full deep-dive with code examples


The Safety Net Analogy

Circus performers use safety nets:

  • Allows them to try risky moves
  • Catches them if they fall
  • Confidence to perform better

Tests are safety nets for code!

They catch bugs before users do.


Why Test?

Code breaks when you:

  • Add new features
  • Fix bugs (and accidentally create new ones)
  • Update dependencies
  • Refactor old code

Without tests, you often discover problems when users complain.


Types of Tests

Unit tests:

  • Test tiny pieces (one function)
  • Fast to run
  • "Does this function add numbers correctly?"

Integration tests:

  • Test pieces working together
  • "Does the login system work with the database?"

End-to-end tests:

  • Test the whole system like a user would
  • "Can a user sign up, browse products, and checkout?"

The Testing Pyramid

      /\        E2E tests
     /  \       (few, slow)
    /────\
   /      \     Integration tests
  /────────\    (some)
 /          \
/────────────\  Unit tests
              (many, fast)

More unit tests (fast, cheap), fewer E2E tests (slow, expensive).


A Simple Example

Function that adds numbers:

add(2, 3) should equal 5
add(-1, 1) should equal 0
add(0, 0) should equal 0

If any fail, something isn’t working as expected.


Benefits of Testing

  • Confidence β†’ Change code without fear
  • Documentation β†’ Tests show how code should work
  • Faster debugging β†’ Tests point to what broke
  • Better design β†’ Testable code is usually cleaner code

In One Sentence

Testing automatically checks if your code works correctly, catching bugs before they reach users.


πŸ”— Enjoying these? Follow for daily ELI5 explanations!

Making complex tech concepts simple, one day at a time.

More from this blog

esreekarreddy

132 posts