20180925-4 单元测试
作业要求参见https://edu.cnblogs.com/campus/nenu/2018fall/homework/2146
1、测试随机生成
import unittest from f4_1 import createOperator class testCreateOperator(unittest.TestCase): def test_CreateOperator(self): print("单元测试开始:") operator = ["+", "-", "*", "/"] self.assertIn(createOperator(self),operator) if __name__ == '__main__': unittest.main()
效果
二、测试生成四则运算试题
import unittest from f4_1 import main class testmain(unittest.TestCase): def test_main(self): print("单元测试开始:") self.assertIn(main(),20) if __name__ == '__main__': unittest.main()