
A test is a check that helps us see whether code behaves as expected. Unit tests and integration tests look at the code from different distances.
A unit test checks one function or class in isolation. For example, a function that calculates a discount can be tested with a price and a discount rate.
expect(calculateDiscount(100, 10)).toBe(90);
This test is quick and points to a small part of the code if it fails.
An integration test checks whether several parts work together. For example, a test might create an order through an API and then check that the order was saved in the database.
Example: testing a car’s brake pedal alone is like a unit test. Driving the car and checking that the pedal slows it down is closer to an integration test.
Unit tests are good for small rules and edge cases. Integration tests are good for finding problems between a controller, database, payment service, or other connected parts.
Neither kind proves that every user journey works. A full browser test can check a complete flow, such as signing in and placing an order, but it is usually slower to run.
Start with the most important rule or connection and write a test that checks the behavior a user depends on.