Created
March 2, 2016 14:42
-
-
Save thigm85/5a34f1febe6daa26364f to your computer and use it in GitHub Desktop.
Code sample for writing python unit tests with the unittest module.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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