待测函数houduan.py
def hanshu1(xc1,xc2):
add=xc1+xc2
return add #要写return,必须要有返回值
测试用例ceshi.py
import unittest
from houduan import hanshu1
class AddTest(unittest.TestCase):
def test_add(self):
testresult=hanshu1(10,20) #测试结果=在测试中调用函数1后的结果
self.assertEqual(testresult,30)#比较测试结果和预期结果是否吻合
unittest.main()
结果输出
.
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
------------------
(program exited with code: 0)
请按任意键继续. . .