Created
February 10, 2013 13:34
-
-
Save gahcep/4749600 to your computer and use it in GitHub Desktop.
Article 'QA in Python - working with unittest'
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 | |
def setUpModule(): | |
print "In setUpModule()" | |
def tearDownModule(): | |
print "In tearDownModule()" | |
class FirstTestClass(unittest.TestCase): | |
''' | |
Invoked without setUp and tearDown methods | |
''' | |
def test_add(self): | |
print "In test_add()" | |
self.assertEquals(120, 100 + 20) | |
class SecondTestClass(unittest.TestCase): | |
''' | |
Invoked with setUpClass/setUp and tearDown/tearDownClass methods | |
''' | |
@staticmethod | |
def setUpClass(): | |
print "In setUpClass()" | |
def setUp(self): | |
print "In setUp()" | |
def test_sub(self): | |
print "In test_sub()" | |
self.assertEquals(210, 110 * 2 - 10) | |
self.assertEquals(170, 140 - (-30)) | |
def test_mul(self): | |
print "In test_mul()" | |
self.assertEquals(420, 210 * 2) | |
self.assertEquals(420, 210 * 2.0000000000000000000001) | |
def tearDown(self): | |
print "In tearDown()" | |
@staticmethod | |
def tearDownClass(): | |
print "In tearDownClass()" | |
if __name__ == '__main__': | |
unittest.main() | |
# CLI run options | |
# - pyexample_3.py |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment