Testing Questions and Answers

Take Exam

Python Programming - Testing Questions with Answers introduce concepts of verifying code reliability using unit tests. These Python Testing Questions are essential for Infosys, Accenture, and Capgemini exams to evaluate coding accuracy and debugging skills

Testing

Showing 10 of 25 questions

1. Which of the following is a Python unit testing framework?

  • A) pytest
  • B) numpy
  • C) tkinter
  • D) matplotlib
Show Answer Report

2. The unittest module in Python is based on which programming concept?

  • A) Functional programming
  • B) Object-oriented programming
  • C) Modular programming
  • D) Procedural programming
Show Answer Report

3. What is the main purpose of Python's assert statement?

  • A) To handle exceptions
  • B) To check a condition and raise error if false
  • C) To define variables
  • D) To import modules
Show Answer Report

4. Which method is used in unittest to run code before each test method?

  • A) setup()
  • B) beforeTest()
  • C) setUp()
  • D) init()
Show Answer Report

5. What should a test method name in unittest usually start with?

  • A) run_
  • B) check_
  • C) test_
  • D) case_
Show Answer Report

6. Which function runs all tests in a unittest class when called in the main block?

  • A) unittest.main()
  • B) unittest.run()
  • C) unittest.execute()
  • D) TestRunner.run()
Show Answer Report

7. Which exception is raised when an assert statement fails?

  • A) AssertionError
  • B) TypeError
  • C) ValueError
  • D) TestError
Show Answer Report

8. Which of the following can be used as an alternative testing framework to unittest?

  • A) pandas
  • B) doctest
  • C) sqlite3
  • D) itertools
Show Answer Report

9. In pytest, which of the following naming conventions helps detection of test functions?

  • A) Functions starting with print_
  • B) Functions starting with test_
  • C) Functions named Example_
  • D) Functions ending with _method
Show Answer Report

10. Which function checks equality between two values in unittest?

  • A) checkEqual()
  • B) assertSame()
  • C) assertEqual()
  • D) testEqual()
Show Answer Report
Questions and Answers for Competitive Exams Various Entrance Test