NewWork mode: your Claude Code or Codex on work calls, answering from your project's codeSkip to content
Middle+2 views

Can you explain the main difference between unit tests and integration tests, and in what situations do you use Mockito when writing unit tests?

Practice

Asked at

AI answer

A unit test checks a small unit of logic in isolation, usually without a database or network. An integration test checks how components interact—for example, an application with PostgreSQL, an HTTP client, or a queue—and therefore more often uses real dependencies or test versions of them. I use Mockito in unit tests to replace external dependencies with mock objects, define their responses, and verify important interactions. For example, a service can be tested with a mocked repository. The logic being tested itself is usually not mocked; it’s also best not to over-verify internal calls when checking the result is sufficient.