DEV Community

Discussion on: Explain Unit Testing like I'm five

Collapse
kalpeshbdarji profile image
Kalpesh Darji • Edited on

The baseline of Unit testing is that it tests every piece of code in isolation without dependencies.

Let's understand it with the example of making a breakfast, e.g.Omelet.

Here you check the quality and quantity of each ingredient to make a delicious Omelet.

  • How many eggs? Are they fresh?
  • What kind of milk? How much? Is it spoiled?
  • Is your bowl (for scrambling) clean?
  • And so on...

Here you are checking each ingredient separately without mixing them. You’re doing a unit testing in this sense. You’re testing your work and units that will comprise the product.

But note that you’re not testing the product.

Now, let's say you found eggs unhealthy. Here you know that those eggs are going to ruin your morning and hence you will replace them with fresh eggs. That's the main benefit of unit testing where you can identify the piece of code which will cause a problem in future.

When you taste the omelet, you are doing Integration testing. Integration testing checks that whether all the components work together as expected.

P.S: Those who are older than five and want to dig more about Unit testing, can read this blog: simform.com/unit-testing-tdd

Collapse
cat profile image
Cat

This one wins. Thank you.

Collapse
nestedsoftware profile image
Nested Software

I really like this answer!