Testing Questions and Answers
Practice ModeShowing 10 of 25 questions
Q1
Which of the following is a Python unit testing framework?
Answer: Option A
Explanation: pytest is widely used for writing small tests in Python.
Q2
The unittest module in Python is based on which programming concept?
Answer: Option B
Explanation: Each test case is written as a class derived from unittest.TestCase.
Q3
What is the main purpose of Python's assert statement?
Answer: Option B
Explanation: It is commonly used in debugging and testing.
Q4
Which method is used in unittest to run code before each test method?
Answer: Option C
Explanation: setUp() prepares the environment for each test method.
Q5
What should a test method name in unittest usually start with?
Answer: Option C
Explanation: unittest automatically discovers methods that start with this prefix.
Q6
Which function runs all tests in a unittest class when called in the main block?
Answer: Option A
Explanation: It is usually placed under if __name__ == "__main__":.
Q7
Which exception is raised when an assert statement fails?
Answer: Option A
Explanation: The name itself indicates assertion failure.
Q8
Which of the following can be used as an alternative testing framework to unittest?
Answer: Option B
Explanation: It tests code examples embedded in docstrings.
Q9
In pytest, which of the following naming conventions helps detection of test functions?
Answer: Option B
Explanation: pytest automatically collects functions with that prefix.
Q10
Which function checks equality between two values in unittest?
Answer: Option C
Explanation: It verifies the expected value equals the actual value.