← All topics
Quiz: Testing Python Code: questions with answers
10 questions, each with the answer and a short explanation.
Take the timed quiz + get a certificate →- Q1. What happens when assert x 0, "x must be positive" runs with x = -2?
- Q2. Why should you not use assert to validate user input in a real program?
- Q3. In unittest, which methods of a TestCase class are run as tests?
- Q4. What is setUp used for?
- Q5. What does this print? (code)
- Q6. A function gives free delivery for orders of Rs 500 or more. Which set of test inputs is best?
- Q7. What does @pytest.mark.parametrize do?
- Q8. doctest.testmod() returns TestResults(failed=0, attempted=3). What does this mean?
- Q9. In TDD, what is the first step of the cycle?
- Q10. How should you compare two float results in a unittest test?