1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Testing in Python

Exercise

Factorial with unittest

In this exercise, you will start using unittest to create basic tests for the factorial function. Since the library uses an object-oriented approach, the functions will be implemented as methods of a unittest.TestCase class. The unittest package has already been imported.

Instructions 1/3

undefined XP
  • 1
    • Use .assertEqual() to check that the factorial of 5 equals 120.
  • 2
    • Use .assertEqual() to check that the factorial of 0 equals 1.
  • 3
    • Use .assertRaises() to create a test for checking that the factorial of a negative number will raise a ValueError.