Testing Questions and Answers

Practice Mode
Showing 10 of 25 questions
Q11
What does the command pytest -v do?
  • A A) Runs pytest in visual mode
  • B B) Displays detailed output for each test case
  • C C) Deletes previous test results
  • D D) Installs pytest
Answer: Option B
Explanation: The -v flag stands for verbose mode.
Q12
What is the output if all assert statements pass in a test file?
  • A A) Failure message
  • B B) Error traceback
  • C C) Success message
  • D D) No output
Answer: Option C
Explanation: pytest or unittest usually prints "OK" if all pass.
Q13
What does assertTrue() in unittest check?
  • A A) If the value is False
  • B B) If the value is None
  • C C) If the expression is True
  • D D) If the value is zero
Answer: Option C
Explanation: It fails if the given expression evaluates to False.
Q14
Which method is used to perform cleanup after each test in unittest?
  • A A) tearDown()
  • B B) afterTest()
  • C C) cleanUp()
  • D D) removeTest()
Answer: Option A
Explanation: It is executed right after each test case.
Q15
What is the default behavior when an assert fails in pytest?
  • A A) Test skips automatically
  • B B) Exception is ignored
  • C C) Test fails and stops at that point
  • D D) System restarts
Answer: Option C
Explanation: pytest halts failed tests and reports them.
Q16
What is mock used for in testing?
  • A A) To decorate functions
  • B B) To simulate objects or behavior
  • C C) To compile code faster
  • D D) To hide test results
Answer: Option B
Explanation: It helps isolate the code being tested.
Q17
When using pytest.raises, you generally test for what?
  • A A) returned value correctness
  • B B) time efficiency
  • C C) expected exceptions
  • D D) output formatting
Answer: Option C
Explanation: It ensures that a function raises a specific error.
Q18
What is the output of assert "a" in "apple"?
  • A A) AssertionError
  • B B) True
  • C C) False
  • D D) ValueError
Answer: Option B
Explanation: The substring "a" exists in "apple".
Q19
Which command runs all tests in the current directory using pytest?
  • A A) pytest .
  • B B) python run_tests
  • C C) pytest all
  • D D) python -m unittest
Answer: Option A
Explanation: The dot indicates the current directory.
Q20
What is test coverage in testing?
  • A A) Number of test files
  • B B) Portion of code executed during testing
  • C C) Compilation speed
  • D D) Function name length
Answer: Option B
Explanation: Coverage helps to measure testing completeness.
Questions and Answers for Competitive Exams Various Entrance Test