Exercise: Testing

Questions for: Testing

Which assertion method in the unittest module is used to check if two values are not equal?
A:
assertEqual
B:
assertNotEqual
C:
assertTrue
D:
assertNot
Answer: B
The assertNotEqual method in the unittest module is used to check if two values are not equal during testing.
What is the purpose of the setUp method in a Python test class?
A:
It signals the start of the test class
B:
It initializes resources before each test method is executed
C:
It marks a test as skipped
D:
It defines the teardown logic for a test case
Answer: B
The setUp method in a Python test class is used to initialize resources or perform setup tasks before each test method is executed.
How can you check if a Python function raises a specific exception during testing?
A:
Use the assertRaises method from the unittest module
B:
Utilize the expectException decorator
C:
Employ the checkException function in the testing module
D:
Insert a try-except block and manually check for the exception
Answer: A
The assertRaises method in the unittest module is used to check if a specific exception is raised by a Python function during testing.
Ad Slot (Above Pagination)
Quiz