自動化測試概要

案例研究:用 Python 建構軟體

Mark Pedigo

Principal Data Scientist

路線圖

專案路線圖,標示已完成與即將開始的部分。

案例研究:用 Python 建構軟體

自動化測試與開發流程

  • 正確、可預期的結果
  • 預先定義的測試案例
  • 自動執行

電腦螢幕顯示「automated testing」,周圍有程式錯誤與齒輪,代表自動化測試。

案例研究:用 Python 建構軟體

doctest 函式庫

  • 自動化測試:doctestpytest
  • 用 docstring 描述程式碼
  • doctest:驗證 docstring 範例
案例研究:用 Python 建構軟體

doctest 的功能

  • 內嵌測試
  • 易於使用
  • 文件即測試
  • 支援回歸測試
案例研究:用 Python 建構軟體

使用範例

def area(l, w):
    """
    Finds the area given length and width and returns the result
    >>> area(1, 1)
    1
    """
    return l + w

import doctest
doctest.testmod()
案例研究:用 Python 建構軟體

使用範例

Failed example:
    area(1,1)
Expected:
    1
Got:
    2
案例研究:用 Python 建構軟體

使用範例

def area(l, w):
    """
    Finds the area given length and width and returns the result
    >>> area(1, 1)
    1
    """
    return l * w

import doctest
doctest.testmod()

一切正常=沒有錯誤訊息、沒有輸出

案例研究:用 Python 建構軟體

一起來練習吧!

案例研究:用 Python 建構軟體

Preparing Video For Download...