Skip to content

Instantly share code, notes, and snippets.

@thigm85
Created March 2, 2016 14:42
Show Gist options
  • Save thigm85/5a34f1febe6daa26364f to your computer and use it in GitHub Desktop.
Save thigm85/5a34f1febe6daa26364f to your computer and use it in GitHub Desktop.
Code sample for writing python unit tests with the unittest module.
import unittest
# Subclass TestCase class
class TestUM(unittest.TestCase):
# Execute code prior to unit tests being run
def setUp(self):
pass
# create unit tests using assert methods
def test_numbers_3_4(self):
self.assertEqual( multiply(3,4), 12)
# return informative failure messages
def testFail(self):
self.assertFalse(True, 'failure message goes here')
# Add the following at the end of each test file to run the tests
# Then use 'python unittest_file.py -v' to run the tests
# 'v' flag for verbose
if __name__ == '__main__':
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment