Exercise: Testing

Questions for: Testing

What is the purpose of the @mock.patch decorator in Python testing?
A:
Decorates a test method with a patch
B:
Simulates the behavior of real objects in a controlled way
C:
Skips a test method
D:
Marks a test as skipped
Answer: A
The @mock.patch decorator in Python is used to decorate a test method with a patch for mocking.
What does the Python unittest.skipTest decorator indicate?
A:
Expects a failure and marks the test as passed if it fails
B:
Expects a failure and marks the test as failed if it passes
C:
Skips the test unless a condition is True
D:
Marks the current test as skipped
Answer: D
The unittest.skipTest decorator is used to mark the current test as skipped in Python unittest.
What is the purpose of the unittest.mock.side_effect attribute?
A:
Checks if a function or method has been called
B:
Represents the call arguments of a function or method
C:
Mocks the behavior of a function or method
D:
Defines the return values of a function or method
Answer: C
The unittest.mock.side_effect attribute is used to define the behavior (side effect) of a function or method in Python unittest.mock.
In Python's unittest module, what does the assertRegex method check?
A:
If a value is within a specified range
B:
If a condition is True
C:
If a value matches a regular expression
D:
If two values are equal
Answer: C
The assertRegex method in the unittest module checks if a value matches a specified regular expression during testing.
What does the Python unittest.TestCase.subTest() method provide?
A:
A method to create sub-tests within a test case
B:
A way to skip parts of a test case
C:
Access to the current test case instance
D:
A method to check if a condition is true
Answer: A
The unittest.TestCase.subTest() method is used to create sub-tests within a test case in Python unittest.
Ad Slot (Above Pagination)
Quiz