Testing Questions and Answers
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
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
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
4. Which method is used in unittest to run code before each test method?
- A) setup()
- B) beforeTest()
- C) setUp()
- D) init()
5. What should a test method name in unittest usually start with?
- A) run_
- B) check_
- C) test_
- D) case_
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()
7. Which exception is raised when an assert statement fails?
- A) AssertionError
- B) TypeError
- C) ValueError
- D) TestError
8. Which of the following can be used as an alternative testing framework to unittest?
- A) pandas
- B) doctest
- C) sqlite3
- D) itertools
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
10. Which function checks equality between two values in unittest?
- A) checkEqual()
- B) assertSame()
- C) assertEqual()
- D) testEqual()