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