测试
12test_requests.pyimport unittest测试函数
ljq.py12345def sum(x,y):return x+ydef sub(x,y):return x-ytest_ljq.py
123456789101112131415161718#!/usr/bin/env pythonimport unittestimport ljqclass mytest(unittest.TestCase):def setUp(self):passdef tearDown(self):passdef testsum(self):self.assertEqual(ljq.sum(1,2),3)def testsub(self):self.assertEqual(ljq.sub(2,1),1)if __name__ == '__main__':unittest.main()测试类
12345678class myclass():def __init__(self):passdef sum(self,x,y):return x+ydef sub(self,x,y):return x-y#!/usr/bin/env python
import unittest
import ljqclass mytest(unittest.TestCase):
def setUp(self):self.tclass = ljq.myclass()
def tearDown(self):
pass
def testsum(self):
self.assertEqual(ljq.sum(1,2),3)
def testsub(self):
self.assertEqual(ljq.sub(2,1),1)
if __name__ == '__main__':
unittest.main()
```