How do unit and integration tests differ?
A unit test checks a small behavior with limited dependencies; an integration test checks components working together.
How it works and where it is used
Unit tests give quick feedback on calculations and validation. Integration tests can catch real database, file or service-contract faults. Excessive mocks may test an application agreeing with itself while missing true contract failures. Testing every small rule through slow end-to-end flows is also costly.
Limits, safety and selection criteria
Choose based on risk and where a fault can occur. A critical payment flow needs both fast domain tests and realistic component interaction. A test that identifies the broken boundary is more useful than one that only fails broadly. A discount formula tested as an isolated function is a unit example. Checking that orders and payment records reflect it is integration testing; a user checkout flow is broader still. Putting every scenario at one level sacrifices either speed or realism. Contract tests can expose differences between a test double and the actual service. Define what each level is expected to catch so failures remain diagnosable. A simple unit test and one realistic payment integration test can complement each other better than dozens of brittle browser scripts.