单元测试-unittest模块

一、简单的一个实例python

 1 import unittest
 2 
 3 def calc(a,b):
 4     return a+b
 5 class MyTest(unittest.TestCase):
 6     def testa(self):#函数名前面加上test
 7         res = calc(1,2)
 8         self.assertEqual(3,res,msg='预期结果和实际结果不一致')#预期结果3,实际结果res,若是不符合预期,提示msg
 9     def testb(self):
10         res = calc(0,1)
11         self.assertEqual(2,res,msg='预期结果和实际结果不一致')
12 unittest.main()

 

  

右键运行时若是出现如下状况,则先别点,先按下面步骤处理下:点击Run-run,而后选择你要运行的文件。就行了。函数

 

 

Pycharm上python运行和unittest运行两种执行方式解析

https://blog.csdn.net/weixin_33724570/article/details/93426672spa

相关文章
相关标签/搜索