Skip to content

Instantly share code, notes, and snippets.

@ls0f
Created December 3, 2014 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ls0f/b80e3f3dbb5d9ad61797 to your computer and use it in GitHub Desktop.
Save ls0f/b80e3f3dbb5d9ad61797 to your computer and use it in GitHub Desktop.
python unittest
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()
@ls0f
Copy link
Author

ls0f commented Dec 3, 2014

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment