Exercise: Testing

Questions for: Testing

In Python testing, what is the purpose of the unittest.mock.Mock class?
A:
Marks a test as skipped
B:
Simulates the behavior of real objects in a controlled way
C:
Represents a placeholder for a real object
D:
Decorates a test method with a patch
Answer: B
The unittest.mock.Mock class in Python is used to simulate the behavior of real objects in a controlled way during testing.
What is the purpose of the unittest.mock.call_count attribute?
A:
Counts the number of calls to a function or method
B:
Checks if a function or method has been called
C:
Represents the call arguments of a function or method
D:
Mocks the behavior of a function or method
Answer: A
The unittest.mock.call_count attribute is used to count the number of calls to a function or method in Python unittest.mock.
Which method in the unittest module is used to assert that a given condition is true?
A:
assertTrue
B:
assertEqual
C:
assertFalse
D:
assertNotEqual
Answer: A
The assertTrue method in the unittest module is used to assert that a given condition is true during testing.
What does the Python unittest.skipTest function do?
A:
Skips the entire test case
B:
Skips the next test method
C:
Skips the next test case
D:
Marks the current test as skipped
Answer: D
The unittest.skipTest function is used to mark the current test as skipped in Python unittest.
What does the Python unittest.expectedFailure 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:
Decorates the test method with a patch for mocking
Answer: A
The unittest.expectedFailure decorator indicates that a test is expected to fail, and if it does fail, it is marked as passed.
Ad Slot (Above Pagination)
Quiz