-
Notifications
You must be signed in to change notification settings - Fork 0
4.1 Unittest
Barak Haim edited this page Apr 30, 2021
·
4 revisions
unittest Assertions cheat sheet
Python Tutorial: Unit Testing Your Code with the unittest Module on youtube
# For a local module named "matrix"
from matrix import *
import unittest
# In order to use testing functionality you must create
# a class inheriting 'unittest.TestCase'
class test_matrix(unittest.TestCase):
# Tests are functions
# Test names prefix with 'test'
def test_multiply_vec_by_scalar(self):
v = multiply_vec_by_scalar([1,1,1],2)
self.assertEqual(v, [2,2,2])
self.assertIsInstance(v, list)
# There are a few ways to run unittests
# Some ways allows for automatic tests detection
# The following way allows us to run the tests inside this
# file by calling it as a normal .py file
if __name__ == '__main__':
unittest.main()