Testing interview questions
Controller Testing, Integration Testing, Mocking with Mockito, Unit Testing with JUnit
80 questions with answers and explanations · 80 flashcards
Questions (page 1 of 2)
- In a Gradle project, how can you ensure that integration tests are only run after unit tests have passed?Multiple choiceHard
- How can build tools like Maven help manage library dependencies in Java projects?Multiple choiceMedium
- Why might you choose to use integration tests over unit tests for certain components in an e-commerce application?Multiple choiceHard
- Which benefit of automated unit testing is most critical for maintaining large Java projects?Multiple choiceEasy
- How would you explain a significant advantage of using mocks at the boundary of a system, rather than the internals in an interview?Multiple choiceMedium
- Why do teams use Mockito for mocking dependencies in tests in production code?Multiple choiceMedium
- In a unit test using Mockito, why would you use 'when-thenReturn'?Multiple choiceMedium
- When using Testcontainers for integration testing, why might a developer choose to reuse containers across tests?Multiple choiceHard
- Why is it not recommended to include business logic in JUnit test methods?Multiple choiceMedium
- Why can using extensive integration tests in a large application become a problem in practice?Multiple choiceMedium
- Why do teams use assertions in JUnit tests in production code?Multiple choiceEasy
- In the context of an e-commerce application, what is an advantage of using integration tests over unit tests for testing the checkout process?Multiple choiceHard
- Which Maven lifecycle phase is responsible for compiling source code?Multiple choiceMedium
- Why do teams use Testcontainers for integration testing in a Java application in production code?Multiple choiceEasy
- In a Spring Boot application, which annotation is used to limit the test scope to only the controller layer?Multiple choiceMedium
- Why does the @SpringBootTest annotation in a test class matter in this design?Multiple choiceMedium
- In a Spring Boot test, how can you assert that a JSON response contains a specific field with the expected value?Multiple choiceMedium
- In a test using Mockito, what is the effect of calling 'doReturn()' instead of 'when()'?Multiple choiceMedium
- Why do teams use @WebMvcTest in a Spring Boot application in production code?Multiple choiceEasy
- In the context of a Java e-commerce application, what is a potential pitfall of using real external payment systems in integration tests?Multiple choiceHard
- Why does the 'test' phase in Maven's lifecycle matter in practice?Multiple choiceEasy
- In a Mockito test, what is the purpose of using 'verifyNoMoreInteractions()' on a mock object?Multiple choiceHard
- Which testing framework is widely used in Java for writing integration tests?Multiple choiceEasy
- In a Maven multi-module project, where should shared integration test resources be placed to avoid duplication?Multiple choiceHard
- How does Gradle differ from Maven in terms of build configuration?Multiple choiceMedium
- In a Maven project, where should you define your test dependencies to ensure they are included only in the test classpath?Multiple choiceMedium
- In the context of using Mockito, what does the method 'verify()' do?Multiple choiceEasy
- Which of the following is a potential risk of overusing mocks in unit tests?Multiple choiceHard
- When mocking a dependency with Mockito, what method is used to specify the behavior of a method call?Multiple choiceMedium
- Which of the following is a trade-off when using real SQL databases in integration tests?Multiple choiceEasy
- Why do teams use integration tests over unit tests in an e-commerce application in production code?Multiple choiceMedium
- How would you explain a key difference between unit tests and integration tests in an interview?Multiple choiceMedium
- Which change is best verified with a fast unit test rather than an integration test?Multiple choiceEasy
- In a multi-module Maven project, what is the most effective way to manage dependency versions across all modules?Multiple choiceHard
- Why does the 'verify' phase in a Maven build lifecycle matter in this design?Multiple choiceMedium
- Which of the following is NOT a typical use case for Mockito in integration testing?Multiple choiceMedium
- When using Mockito in integration tests, what is a common use case?Multiple choiceMedium
- Which build tool lifecycle phase is responsible for running tests in a Maven project?Multiple choiceEasy
- Why can mocking internal dependencies too extensively in unit tests become a problem in production code?Multiple choiceHard
- Which phase of the Maven build lifecycle is responsible for compiling the source code?Multiple choiceEasy
- How would you explain an important consideration when writing unit tests for a Java method that interacts with a database in an interview?Multiple choiceMedium
- What issue can arise if you skip integration tests in a continuous integration pipeline for an e-commerce application?Multiple choiceHard
- Why can manual UI testing compared to automated testing become a problem in practice?Multiple choiceEasy
- What does the Maven 'clean' lifecycle phase do?Multiple choiceEasy
- Why can using real databases in integration tests become a problem in practice?Multiple choiceMedium
- In Gradle, which configuration is used to declare dependencies required only for compiling the main source code?Multiple choiceMedium
- If a JUnit test for an e-commerce shopping cart fails intermittently, what might be a likely cause?Multiple choiceHard
- In a large e-commerce system, what is a downside of using too many integration tests compared to unit tests?Multiple choiceHard
- Which test type is the best fit for verifying JPA mappings, SQL queries, or transaction boundaries?Multiple choiceHard
- Which of the following statements about integration tests is true regarding their execution time compared to unit tests?Multiple choiceMedium