Testing Questions and Answers

Practice Mode
Showing 10 of 25 questions
Q1
Which of the following is a Python unit testing framework?
  • A A) pytest
  • B B) numpy
  • C C) tkinter
  • D D) matplotlib
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?
  • A A) Functional programming
  • B B) Object-oriented programming
  • C C) Modular programming
  • D D) Procedural programming
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?
  • A A) To handle exceptions
  • B B) To check a condition and raise error if false
  • C C) To define variables
  • D D) To import modules
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?
  • A A) setup()
  • B B) beforeTest()
  • C C) setUp()
  • D D) init()
Answer: Option C
Explanation: setUp() prepares the environment for each test method.
Q5
What should a test method name in unittest usually start with?
  • A A) run_
  • B B) check_
  • C C) test_
  • D D) case_
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?
  • A A) unittest.main()
  • B B) unittest.run()
  • C C) unittest.execute()
  • D D) TestRunner.run()
Answer: Option A
Explanation: It is usually placed under if __name__ == "__main__":.
Q7
Which exception is raised when an assert statement fails?
  • A A) AssertionError
  • B B) TypeError
  • C C) ValueError
  • D D) TestError
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?
  • A A) pandas
  • B B) doctest
  • C C) sqlite3
  • D D) itertools
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?
  • A A) Functions starting with print_
  • B B) Functions starting with test_
  • C C) Functions named Example_
  • D D) Functions ending with _method
Answer: Option B
Explanation: pytest automatically collects functions with that prefix.
Q10
Which function checks equality between two values in unittest?
  • A A) checkEqual()
  • B B) assertSame()
  • C C) assertEqual()
  • D D) testEqual()
Answer: Option C
Explanation: It verifies the expected value equals the actual value.
Questions and Answers for Competitive Exams Various Entrance Test