Exercise: Testing

Questions for: Testing

What is the purpose of the unittest.mock.MagicMock.return_value attribute?
A:
Specifies the return value of a method
B:
Specifies the call count of a method
C:
Specifies the exception to be raised by a method
D:
Specifies the side effect of a method
Answer: A
The return_value attribute in Python unittest.mock.MagicMock is used to specify the return value of a method.
What does the unittest.mock.Mock.assert_called_with method validate in Python testing?
A:
Asserts that a method was called exactly once
B:
Asserts that a method was not called
C:
Asserts that a method was called with specific arguments
D:
Asserts that a method was called with any arguments
Answer: C
The assert_called_with method in Python unittest.mock.Mock asserts that a method was called with specific arguments.
In Python's unittest module, what is the purpose of the unittest.skipUnless decorator?
A:
Skips the entire test case
B:
Skips the next test method
C:
Skips the test unless a condition is True
D:
Marks the test as skipped
Answer: C
The unittest.skipUnless decorator is used to skip a test unless a specified condition is True in Python's unittest module.
What is the purpose of the unittest.mock.Mock.reset_mock method?
A:
Resets the call count of a method
B:
Resets the return value of a method
C:
Resets the side effect of a method
D:
Resets all attributes of a mock object
Answer: D
The reset_mock method in Python unittest.mock.Mock resets all attributes of a mock object.
What is the purpose of the unittest.mock.patch.object decorator in Python testing?
A:
Decorates a test method with a patch for a class method
B:
Skips a test method based on a condition
C:
Creates a magical mock object for all methods of a class
D:
Marks a test as skipped
Answer: A
The unittest.mock.patch.object decorator is used to decorate a test method with a patch for a class method in Python.
Ad Slot (Above Pagination)
Quiz