Mocking Frameworks MCQs

  1. Which of the following is a popular Java mocking framework?
    a) Mockito
    b) JUnit
    c) PyTest
    d) NUnit
    View Answer

    Correct answer: A — Mockito

  2. In Python, the standard library for mocking is:
    a) unittest.mock
    b) pytest.mock
    c) mockito.py
    d) pyfake
    View Answer

    Correct answer: A — unittest.mock

  3. JMockit is primarily used for:
    a) Mocking and stubbing in Java
    b) Logging in Java
    c) Deployment in Java
    d) Monitoring in Java
    View Answer

    Correct answer: A — Mocking and stubbing in Java

  4. Which Mockito method verifies method calls?
    a) verify()
    b) check()
    c) assertCall()
    d) confirm()
    View Answer

    Correct answer: A — verify()

  5. In unittest.mock, which function creates a mock object?
    a) Mock()
    b) Fake()
    c) Stub()
    d) Spy()
    View Answer

    Correct answer: A — Mock()

  6. Which of the following is NOT a mocking concept?
    a) Stubbing
    b) Spying
    c) Verifying
    d) Compiling
    View Answer

    Correct answer: D — Compiling

  7. Mockito's when(...).thenReturn(...) is used for:
    a) Stubbing behavior
    b) Logging output
    c) Monitoring calls
    d) Deploying code
    View Answer

    Correct answer: A — Stubbing behavior

  8. In unittest.mock, patch() is used to:
    a) Replace objects during tests
    b) Deploy applications
    c) Monitor logs
    d) Run CI/CD pipelines
    View Answer

    Correct answer: A — Replace objects during tests

  9. JMockit supports mocking of:
    a) Static methods
    b) Only instance methods
    c) Only constructors
    d) Only private methods
    View Answer

    Correct answer: A — Static methods

  10. Which of the following best describes a stub?
    a) Provides predefined responses
    b) Records method calls
    c) Deploys applications
    d) Monitors logs
    View Answer

    Correct answer: A — Provides predefined responses

  11. What will be printed?
    1 import static org.mockito.Mockito.*;
    2 public class EduinqMockTest {
    3 public static void main(String[] args) {
    4 List<String> mockList = mock(List.class);
    5 when(mockList.size()).thenReturn(5);
    6 System.out.println("Eduinq size: " + mockList.size());
    7 }
    8 }
    a) Eduinq size: 5
    b) Eduinq size: 0
    c) Eduinq size: null
    d) Compilation error
    View Answer

    Correct answer: A — Eduinq size: 5

  12. In unittest.mock, MagicMock differs from Mock by:
    a) Supporting magic methods
    b) Supporting only static methods
    c) Supporting only private methods
    d) Supporting only constructors
    View Answer

    Correct answer: A — Supporting magic methods

  13. Mockito's spy() is used to:
    a) Wrap real objects and monitor calls
    b) Create fake objects only
    c) Deploy applications
    d) Monitor logs
    View Answer

    Correct answer: A — Wrap real objects and monitor calls

  14. Which of the following is true about mocks?
    a) They simulate dependencies
    b) They replace CI/CD pipelines
    c) They monitor production logs
    d) They deploy containers
    View Answer

    Correct answer: A — They simulate dependencies

  15. JMockit supports verification using:
    a) Verifications block
    b) assertVerify
    c) checkCalls
    d) confirmCalls
    View Answer

    Correct answer: A — Verifications block

  16. In unittest.mock, side_effect is used to:
    a) Define custom behavior or exceptions
    b) Deploy applications
    c) Monitor logs
    d) Run CI/CD pipelines
    View Answer

    Correct answer: A — Define custom behavior or exceptions

  17. Mockito supports argument capturing using:
    a) ArgumentCaptor
    b) ArgCapture
    c) CaptureArgs
    d) ParamCaptor
    View Answer

    Correct answer: A — ArgumentCaptor

  18. Which of the following is NOT a Python mocking tool?
    a) unittest.mock
    b) pytest-mock
    c) JMockit
    d) MagicMock
    View Answer

    Correct answer: C — JMockit

  19. JMockit supports mocking constructors using:
    a) Expectations block
    b) ConstructorMock
    c) InitMock
    d) BuildMock
    View Answer

    Correct answer: A — Expectations block

  20. Which of the following best describes a spy?
    a) Wraps real objects and records calls
    b) Provides predefined responses only
    c) Deploys applications
    d) Monitors logs
    View Answer

    Correct answer: A — Wraps real objects and records calls

  21. What will be printed?
    1 from unittest.mock import Mock
    2 eduinq_mock = Mock()
    3 eduinq_mock.get_name.return_value = "Eduinq"
    4 print(eduinq_mock.get_name())
    a) Eduinq
    b) None
    c) get_name
    d) Error
    View Answer

    Correct answer: A — Eduinq

  22. Mockito's any() matcher is used for:
    a) Matching any argument
    b) Matching only integers
    c) Matching only strings
    d) Matching only objects
    View Answer

    Correct answer: A — Matching any argument

  23. In unittest.mock, assert_called_once() verifies:
    a) Method was called exactly once
    b) Method was never called
    c) Method was called multiple times
    d) Method was called with arguments
    View Answer

    Correct answer: A — Method was called exactly once

  24. JMockit supports mocking private methods using:
    a) Expectations block
    b) PrivateMock
    c) HiddenMock
    d) SecretMock
    View Answer

    Correct answer: A — Expectations block

  25. Which of the following is true about stubs?
    a) They provide fixed responses
    b) They monitor logs
    c) They deploy applications
    d) They replace CI/CD pipelines
    View Answer

    Correct answer: A — They provide fixed responses

  26. Mockito's doReturn(...).when(...) is used for:
    a) Stubbing void methods
    b) Logging output
    c) Monitoring calls
    d) Deploying code
    View Answer

    Correct answer: A — Stubbing void methods

  27. In unittest.mock, assert_not_called() verifies:
    a) Method was never called
    b) Method was called once
    c) Method was called multiple times
    d) Method was called with arguments
    View Answer

    Correct answer: A — Method was never called

  28. JMockit supports mocking static methods using:
    a) Expectations block
    b) StaticMock
    c) MethodMock
    d) ClassMock
    View Answer

    Correct answer: A — Expectations block

  29. Which of the following best describes verification in mocking?
    a) Ensures expected calls were made
    b) Deploys applications
    c) Monitors logs
    d) Runs CI/CD pipelines
    View Answer

    Correct answer: A — Ensures expected calls were made

  30. PyTest integrates mocking using:
    a) pytest-mock plugin
    b) pytest-fake plugin
    c) pytest-stub plugin
    d) pytest-spy plugin
    View Answer

    Correct answer: A — pytest-mock plugin

  31. What will be printed?
    1 import static org.mockito.Mockito.*;
    2 public class EduinqSpyTest {
    3 public static void main(String[] args) {
    4 List<String> list = new ArrayList<>();
    5 List<String> spyList = spy(list);
    6 spyList.add("Eduinq");
    7 System.out.println(spyList.get(0));
    8 }
    9 }
    a) Eduinq
    b) null
    c) 0
    d) Compilation error
    View Answer

    Correct answer: A — Eduinq

  32. In unittest.mock, call_args stores:
    a) Arguments of the last call
    b) All return values
    c) All exceptions
    d) All mocks
    View Answer

    Correct answer: A — Arguments of the last call

  33. Mockito supports throwing exceptions using:
    a) thenThrow()
    b) throwException()
    c) raiseError()
    d) failWith()
    View Answer

    Correct answer: A — thenThrow()

  34. JMockit supports recording expectations using:
    a) Expectations block
    b) Record block
    c) Mock block
    d) Stub block
    View Answer

    Correct answer: A — Expectations block

  35. Which of the following is true about spies?
    a) They wrap real objects
    b) They only provide fixed responses
    c) They deploy applications
    d) They monitor logs
    View Answer

    Correct answer: A — They wrap real objects

  36. In unittest.mock, assert_called_with() verifies:
    a) Method was called with specific arguments
    b) Method was never called
    c) Method was called multiple times
    d) Method was called without arguments
    View Answer

    Correct answer: A — Method was called with specific arguments

  37. Mockito supports deep stubs using:
    a) mock(Class, RETURNS_DEEP_STUBS)
    b) mock(Class, RETURNS_STUBS)
    c) mock(Class, DEEP)
    d) mock(Class, STUBS)
    View Answer

    Correct answer: A — mock(Class, RETURNS_DEEP_STUBS)

  38. JMockit supports mocking final classes using:
    a) Expectations block
    b) FinalMock
    c) ClassMock
    d) EndMock
    View Answer

    Correct answer: A — Expectations block

  39. Which of the following is true about mocks vs stubs?
    a) Mocks verify interactions, stubs provide responses
    b) Mocks provide responses, stubs verify interactions
    c) Both provide responses only
    d) Both verify interactions only
    View Answer

    Correct answer: A — Mocks verify interactions, stubs provide responses

  40. PyTest's monkeypatch fixture is mainly used for:
    a) Modifying or replacing functions during tests
    b) Deploying applications
    c) Monitoring logs
    d) Running CI/CD pipelines
    View Answer

    Correct answer: A — Modifying or replacing functions during tests

  41. Mockito's reset() method is used to:
    a) Clear interactions and stubs on a mock
    b) Deploy applications
    c) Monitor logs
    d) Run pipelines
    View Answer

    Correct answer: A — Clear interactions and stubs on a mock

  42. In unittest.mock, patch.object() is used to:
    a) Replace attributes of an object
    b) Replace entire modules
    c) Replace CI/CD pipelines
    d) Replace databases
    View Answer

    Correct answer: A — Replace attributes of an object

  43. JMockit supports mocking final methods using:
    a) Expectations block
    b) FinalMock
    c) MethodMock
    d) EndMock
    View Answer

    Correct answer: A — Expectations block

  44. Which of the following is true about spies in Mockito?
    a) They allow partial mocking of real objects
    b) They only provide fixed responses
    c) They deploy applications
    d) They monitor logs
    View Answer

    Correct answer: A — They allow partial mocking of real objects

  45. In unittest.mock, patch.dict() is used to:
    a) Temporarily modify dictionaries
    b) Replace modules
    c) Replace classes
    d) Replace functions
    View Answer

    Correct answer: A — Temporarily modify dictionaries

  46. Mockito's verifyNoMoreInteractions() is used to:
    a) Ensure no unexpected calls were made
    b) Ensure all calls are logged
    c) Ensure deployment is complete
    d) Ensure monitoring is active
    View Answer

    Correct answer: A — Ensure no unexpected calls were made

  47. JMockit supports mocking static initializers using:
    a) Expectations block
    b) InitMock
    c) StaticInitMock
    d) ClassInitMock
    View Answer

    Correct answer: A — Expectations block

  48. Which of the following best describes a fake object?
    a) Provides a working implementation with simplified logic
    b) Provides predefined responses only
    c) Deploys applications
    d) Monitors logs
    View Answer

    Correct answer: A — Provides a working implementation with simplified logic

  49. In unittest.mock, patch.multiple() is used to:
    a) Patch multiple attributes at once
    b) Patch only one attribute
    c) Patch CI/CD pipelines
    d) Patch databases
    View Answer

    Correct answer: A — Patch multiple attributes at once

  50. Which of the following best describes mocking frameworks?
    a) They simulate dependencies for isolated testing
    b) They replace CI/CD pipelines
    c) They monitor production logs
    d) They deploy containers
    View Answer

    Correct answer: A — They simulate dependencies for isolated testing

Quick Links to Explore