Skip to content
Sharp

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)

  1. In a Gradle project, how can you ensure that integration tests are only run after unit tests have passed?Multiple choiceHard
  2. How can build tools like Maven help manage library dependencies in Java projects?Multiple choiceMedium
  3. Why might you choose to use integration tests over unit tests for certain components in an e-commerce application?Multiple choiceHard
  4. Which benefit of automated unit testing is most critical for maintaining large Java projects?Multiple choiceEasy
  5. 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
  6. Why do teams use Mockito for mocking dependencies in tests in production code?Multiple choiceMedium
  7. In a unit test using Mockito, why would you use 'when-thenReturn'?Multiple choiceMedium
  8. When using Testcontainers for integration testing, why might a developer choose to reuse containers across tests?Multiple choiceHard
  9. Why is it not recommended to include business logic in JUnit test methods?Multiple choiceMedium
  10. Why can using extensive integration tests in a large application become a problem in practice?Multiple choiceMedium
  11. Why do teams use assertions in JUnit tests in production code?Multiple choiceEasy
  12. 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
  13. Which Maven lifecycle phase is responsible for compiling source code?Multiple choiceMedium
  14. Why do teams use Testcontainers for integration testing in a Java application in production code?Multiple choiceEasy
  15. In a Spring Boot application, which annotation is used to limit the test scope to only the controller layer?Multiple choiceMedium
  16. Why does the @SpringBootTest annotation in a test class matter in this design?Multiple choiceMedium
  17. In a Spring Boot test, how can you assert that a JSON response contains a specific field with the expected value?Multiple choiceMedium
  18. In a test using Mockito, what is the effect of calling 'doReturn()' instead of 'when()'?Multiple choiceMedium
  19. Why do teams use @WebMvcTest in a Spring Boot application in production code?Multiple choiceEasy
  20. 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
  21. Why does the 'test' phase in Maven's lifecycle matter in practice?Multiple choiceEasy
  22. In a Mockito test, what is the purpose of using 'verifyNoMoreInteractions()' on a mock object?Multiple choiceHard
  23. Which testing framework is widely used in Java for writing integration tests?Multiple choiceEasy
  24. In a Maven multi-module project, where should shared integration test resources be placed to avoid duplication?Multiple choiceHard
  25. How does Gradle differ from Maven in terms of build configuration?Multiple choiceMedium
  26. In a Maven project, where should you define your test dependencies to ensure they are included only in the test classpath?Multiple choiceMedium
  27. In the context of using Mockito, what does the method 'verify()' do?Multiple choiceEasy
  28. Which of the following is a potential risk of overusing mocks in unit tests?Multiple choiceHard
  29. When mocking a dependency with Mockito, what method is used to specify the behavior of a method call?Multiple choiceMedium
  30. Which of the following is a trade-off when using real SQL databases in integration tests?Multiple choiceEasy
  31. Why do teams use integration tests over unit tests in an e-commerce application in production code?Multiple choiceMedium
  32. How would you explain a key difference between unit tests and integration tests in an interview?Multiple choiceMedium
  33. Which change is best verified with a fast unit test rather than an integration test?Multiple choiceEasy
  34. In a multi-module Maven project, what is the most effective way to manage dependency versions across all modules?Multiple choiceHard
  35. Why does the 'verify' phase in a Maven build lifecycle matter in this design?Multiple choiceMedium
  36. Which of the following is NOT a typical use case for Mockito in integration testing?Multiple choiceMedium
  37. When using Mockito in integration tests, what is a common use case?Multiple choiceMedium
  38. Which build tool lifecycle phase is responsible for running tests in a Maven project?Multiple choiceEasy
  39. Why can mocking internal dependencies too extensively in unit tests become a problem in production code?Multiple choiceHard
  40. Which phase of the Maven build lifecycle is responsible for compiling the source code?Multiple choiceEasy
  41. 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
  42. What issue can arise if you skip integration tests in a continuous integration pipeline for an e-commerce application?Multiple choiceHard
  43. Why can manual UI testing compared to automated testing become a problem in practice?Multiple choiceEasy
  44. What does the Maven 'clean' lifecycle phase do?Multiple choiceEasy
  45. Why can using real databases in integration tests become a problem in practice?Multiple choiceMedium
  46. In Gradle, which configuration is used to declare dependencies required only for compiling the main source code?Multiple choiceMedium
  47. If a JUnit test for an e-commerce shopping cart fails intermittently, what might be a likely cause?Multiple choiceHard
  48. In a large e-commerce system, what is a downside of using too many integration tests compared to unit tests?Multiple choiceHard
  49. Which test type is the best fit for verifying JPA mappings, SQL queries, or transaction boundaries?Multiple choiceHard
  50. Which of the following statements about integration tests is true regarding their execution time compared to unit tests?Multiple choiceMedium