qileilove

          blog已經(jīng)轉(zhuǎn)移至github,大家請?jiān)L問 http://qaseven.github.io/

          Python單元測試框架使用unittestpyUnit

           使用Pyunit框架的簡單測試
          '''''
          Created on 2014-4-15
          @author: Administrator
          '''
          import unittest,my_math
          class Test(unittest.TestCase):
          def testIntegers(self):
          for x in xrange(-10,10):
          for y in xrange(-10,10):
          p = my_math.product(x,y)
          self.failUnless(p == x*y,'Integer multiplication faild')
          def testFloat(self):
          for x in  xrange(-10,10):
          for y in xrange(-10,10):
          x = x/10.0
          y = y/10.0
          p = my_math.product(x,y)
          self.failUnless(p == x*y,'Float multiplication faild')
          if __name__ == "__main__":
          #import sys;sys.argv = ['', 'Test.testName']
          unittest.main()
          my_math.py
          '''''
          Created on 2014-4-15
          @author: Administrator
          '''
          def square(x):
          '''''
          Squares a number and return the result.
          >>>square(2)
          4
          >>>square(3)
          9
          '''
          return x*x
          def product(x,y):
          if x == 7 and y ==9:
          return 'bug'
          else:
          return x * y
          #return x*y
          '''''
          if __name__ == '__main__':
          import doctest, my_math
          doctest.testmod(my_math)
          '''
            unittest.main函數(shù)負(fù)責(zé)運(yùn)行測試。它會實(shí)例化所有TestCase的子類,運(yùn)行所有名字以test開頭的方法。
            如果定義了叫做setUp和tearDown的方法,他們就會運(yùn)行在每個測試方法之前和之后執(zhí)行。

          posted on 2014-04-21 12:50 順其自然EVO 閱讀(321) 評論(0)  編輯  收藏 所屬分類: 測試學(xué)習(xí)專欄

          <2014年4月>
          303112345
          6789101112
          13141516171819
          20212223242526
          27282930123
          45678910

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 饶河县| 神木县| 蒙山县| 清徐县| 古交市| 宜章县| 赤城县| 溧阳市| 增城市| 嵩明县| 安宁市| 甘谷县| 高台县| 奇台县| 房山区| 华亭县| 宜州市| 肇庆市| 旌德县| 邯郸县| 通州区| 石棉县| 巫溪县| 阳新县| 九台市| 奇台县| 舒城县| 吉木乃县| 清新县| 乐亭县| 南川市| SHOW| 镇江市| 新兴县| 三原县| 迭部县| 广灵县| 响水县| 屏南县| 彭泽县| 休宁县|