Testing in Action

Sep 16, 2024

Cover image for Testing in Action

Before any discovery is presented to the public, it gets tested over and over again. And guess what? Software is no exception! Today, let's talk about how we make sure our code actually works before we ship it. πŸš€

UI Design vs User Testing

Unit Test

Think of a Unit as a tiny piece of your program. When you want to check if that small piece works correctly, you write unit tests for it. Imagine this: you're a teacher with 10,000 students who all submitted homework. Checking all of them by hand? Impossible! But computers can do it in seconds.

Here's a simple example:

This function takes words and joins them together (you can choose how to separate them with sep). Now, how do we test if it works properly? Let's write a unit test:

I recommend exploring unit tests more. They're perfect for testing classes, methods, and functions. They're like your first line of defense against bugs!

Integration Test

Integration Test Illustration

Let's say you've built an awesome app that thousands of people love. Now you want to add cool new features. But wait - will these new parts work well with the old ones? That's where Integration tests come in!

The word Integration means joining things together. So when you add new features to your app, these tests make sure they play nice with everything else.

There are two main types: Big Bang tests (testing everything at once - like throwing all your toys in a box and seeing if they fit) and Incremental tests (testing small groups of features - like carefully arranging your toys one by one).

Big companies with huge apps usually use the Incremental approach because testing everything at once would take forever!

While unit tests check if individual functions work, integration tests make sure they work together as a team. Here's a simple example:

Functional Test

Functional tests answer one simple question: "Does this thing do what it's supposed to do?" They focus on whether your app solves real business problems correctly. It's not about HOW it works, but WHETHER it works. Think of it like this: "I don't care how the car engine works, I just want it to take me to the grocery store!" πŸ˜„

E2E (End-to-End) Test

End-to-End means testing the whole journey from start to finish. Think of it like this:

  • One end is your server (the chef in a restaurant)
  • The other end is your user (the hungry customer)

E2E tests check if the whole experience works smoothly. It's like having someone secretly test your restaurant by acting like a regular customer - ordering food, paying, and eating - to make sure everything works perfectly from entrance to exit.

These tests pretend to be real users clicking buttons, filling forms, and using your app just like humans would. They're the closest thing to having an army of test users before your real users arrive!

End-to-End testing meme

Canary Test

Here's a cool story: miners used to bring canaries (small birds) into mines. If the bird died, it meant the air was poisonous and humans shouldn't go in. If the bird was fine, the miners knew it was safe.

In software, we do something similar! We release new features to a small group of trusted users first. If they find bugs, they tell us and we fix them. If everything works great, we roll it out to everyone. These brave first users are our "canaries" - testing the air before everyone else jumps in!

Canary test meme

Stress Test

Stress testing is like seeing how much your little brother can annoy you before you lose your cool! πŸ˜‚ You push your system to its limits to see when it breaks.

For example, what happens if a user sends a million requests in a loop? Or tries to upload 50 huge files at once? Will your app crash and burn, or handle it gracefully? Here's a simple stress test:

UI Testing

UI tests check if your app's interface looks and works correctly. Is the text showing up? Are buttons the right color? Is everything where it should be? Here's a simple example for a React app:

Monkey Test

Monkey test meme

Ever seen a toddler with a smartphone? They push random buttons, swipe in crazy directions, and do things you'd never expect. That's basically a monkey test! πŸ’

This genius test (invented by Netflix) checks what happens when users do unpredictable things. If your app survives a monkey test, it can probably handle anything real users throw at it!

This is just a super simple example. Real monkey tests are much wilder!

Fuzz Testing

Imagine you have a form asking for first and last names. Most people will enter actual names, but some crazy folks might type numbers, weird symbols, or even "πŸ‘‘KINGπŸ‘‘".

Fuzz testing throws random, unexpected, or just plain weird data at your program to see if it handles the chaos gracefully. Here's an example in Go:

Others

There are tons of other test types out there! In this article, I've covered some of the most common ones with examples you can actually understand (I hope!).

We might talk about regression tests, security tests, A-B tests, smoke tests, load tests, performance tests, acceptance tests, and more in future posts. Testing might sound boring, but it's actually what keeps the digital world from falling apart! 🌎