Created
December 3, 2014 14:10
-
-
Save ls0f/b80e3f3dbb5d9ad61797 to your computer and use it in GitHub Desktop.
python 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 | |
class Test(): | |
def sub(self,*args): | |
return sum(args) | |
def bigThan5(self,x): | |
if x>5: | |
return True | |
else: | |
return False | |
class autoTestCase(unittest.TestCase): | |
def setUp(self): | |
print "test begin" | |
self.testObj = Test() | |
def tearDown(self): | |
print "test done" | |
pass | |
def testSub(self): | |
self.assertEqual(self.testObj.sub(1,2,3),7) | |
def testBig(self): | |
self.assertTrue(self.testObj.bigThan5(6)) | |
self.assertFalse(self.testObj.bigThan5(5)) | |
if __name__ == "__main__": | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
test begin
test done
.test begin
Ftest done
FAIL: testSub (main.autoTestCase)
Traceback (most recent call last):
File "test.py", line 27, in testSub
self.assertEqual(self.testObj.sub(1,2,3),7)
AssertionError: 6 != 7
Ran 2 tests in 0.000s
FAILED (failures=1)