Can you explain the main difference between unit tests and integration tests, and in what situations do you use Mockito when writing unit tests?
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.
Also asked at WhoAI
- Describe the lifecycle of a Spring bean.
- Could you give me an idea of your salary expectations, both your minimum and your preferred amount?
- What work schedule and format are comfortable for you? Would you consider a 5/2 schedule with a full workload of about 160 hours per month, remote work on Moscow time, a hybrid format while living in [locality] or [region], or working from an office in [locality]? Do you have any scheduling constraints or preferences?
- Tell us how you have used Kafka or another message broker in a microservices architecture, what problems you solved with it, and how you ensured reliable message delivery and processing.
- How do you approach query optimization in PostgreSQL when using JPA Hibernate, and what tools or techniques do you use to reduce database load and improve application performance?
Similar questions
- Explain the main types of test doubles, such as stubs, mocks, and spies. How are they used in testing? What are the differences between them? Give examples of how each type can be used when testing Java applications.
- Explain the concept of Mockito and how it is used in Java application testing.
- What is the difference between using @Spy and @Mock in testing?
- Have you used Testcontainers to write integration tests?
- What is the difference between unit tests and integration tests?