August 2018
Beginner
160 pages
4h 8m
English
Python comes with the built-in unittest module, which is a framework to write automated tests based on JUnit, a unit testing framework for Java. You create tests by subclassing from unittest.TestCase and defining methods that begin with test. Here's an example of a typical minimal test case using unittest:
import unittest from fibo import fibonacci class Test(unittest.TestCase): def test_fibo(self): result = fibonacci(4) self.assertEqual(result, 3) if __name__ == '__main__': unittest.main()
The focus of this example is on showcasing the test itself, not the code being tested, so we will be using a simple fibonacci function. The Fibonacci sequence is an infinite sequence of positive integers where the next ...
Read now
Unlock full access