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 2 of 2)

  1. Why do teams use MockMvc in Spring tests in production code?Multiple choiceEasy
  2. How can you validate that a controller method returns a 404 status code using MockMvc?Multiple choiceMedium
  3. In Java integration testing with Testcontainers, which component is most effectively tested using a real SQL database?Multiple choiceMedium
  4. When using Mockito, why is it important to mock dependencies at the boundaries of a system?Multiple choiceMedium
  5. How can you ensure that a controller method properly handles a thrown exception and returns a specific HTTP status using MockMvc?Multiple choiceHard
  6. Why might you choose to use integration tests sparingly in a large e-commerce application?Multiple choiceHard
  7. How does mocking help in isolating dependencies in integration tests?Multiple choiceHard
  8. Which technique would you use to test a controller method that relies on a complex service layer with multiple dependencies?Multiple choiceHard
  9. Why do teams use a build tool like Maven or Gradle in a Java project in production code?Multiple choiceMedium
  10. In a test using Mockito, how do you specify the behavior of a mock object when a specific method is called?Multiple choiceMedium
  11. When using MockMvc to test a controller, which method would you use to simulate an HTTP GET request?Multiple choiceMedium
  12. In Maven, which phase is responsible for packaging the compiled code into a distributable format?Multiple choiceMedium
  13. Why do teams use MockMvc for testing Spring MVC controllers in production code?Multiple choiceEasy
  14. Why does the 'testCompile' dependency configuration in a Gradle build file matter in this design?Multiple choiceEasy
  15. Why do teams use automated tests over manual tests in an e-commerce application in production code?Multiple choiceEasy
  16. Why would you mock PaymentGateway when unit testing OrderService?Multiple choiceMedium
  17. Why does dependencies in a Maven project matter in this design?Multiple choiceMedium
  18. When using Mockito, what method would you use to verify that a mocked method was called with specific arguments?Multiple choiceMedium
  19. Why might integration tests fail when run on a continuous integration server but pass locally?Multiple choiceHard
  20. Why does the 'test' phase in the Maven build lifecycle matter in this design?Multiple choiceEasy
  21. How can you ensure that a Java method which uses a static utility class is tested in isolation?Multiple choiceHard
  22. What role do fast feedback loops play in preventing regressions?Multiple choiceEasy
  23. In a Gradle project, how can you ensure that integration tests run only after the application has been successfully built?Multiple choiceHard
  24. In Gradle, which task is responsible for executing tests?Multiple choiceEasy
  25. How can you assert that a JSON response from a controller contains a specific field using MockMvc?Multiple choiceMedium
  26. Why do teams use Mockito when testing a payment gateway in an e-commerce application in production code?Multiple choiceEasy
  27. Why is verifying behavior with Mockito preferable over using real network calls in a test?Multiple choiceMedium
  28. What does a controller test mainly try to prove?Multiple choiceMedium
  29. When testing a controller method that returns a list of products, how can you verify the response contains a specific number of items using MockMvc?Multiple choiceHard
  30. Why do teams use Mockito to mock a dependency in a Java test in production code?Multiple choiceEasy