1. 程式人生 > >4 單元測試,結對

4 單元測試,結對

開始 程序 eat .net inf self. clas 分享圖片 技術

此作業要求參見https://edu.cnblogs.com/campus/nenu/2018fall/homework/2146

git,https://git.coding.net/zhaomeizeng/wc.git

一、測試random是否正常

用例

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()

技術分享圖片

通過測試,發現了很多的程序的小Bug和很多沒有註意到的地方。

4 單元測試,結對