Get startedGet started for free

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.

This exercise is part of the course

Introduction to Testing in Python

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

def func_factorial(number):
    if number < 0:
        raise ValueError('Factorial is not defined for negative values')
    factorial = 1
    while number > 1:
        factorial = factorial * number
        number = number - 1
    return factorial

class TestFactorial(unittest.TestCase):
    def test_positives(self):
        # Add the test for testing positives here
        ____
Edit and Run Code