Behave - 入門



讓我們建立一個基本的 Behave 測試。

特性檔案

特性的特性檔案如下所示:

Feature − Payment Types
   
   Scenario − Verify user has two payment options
      Given User is on Payment screen
      When User clicks on Payment types
      Then User should get Types Cheque and Cash

對應的步驟實現檔案

上述特性的對應的步驟實現檔案如下所示:

from behave import *
@given('User is on Payment screen')
def impl_bkpy(context):
      print('User is on Payment screen')
@when('User clicks on Payment types')
def impl_bkpy(context):
      print('User clicks on Payment types')
@then('User should get Types Cheque and Cash')
def impl_bkpy(context):
      print('User should get Types Cheque and Cash')

專案結構

特性“支付型別”的專案結構如下:

Payment Types

輸出

在執行特性檔案之後獲得的輸出如下所示,且此處使用的命令是 behave

Running the Feature File

該輸出顯示了特性和場景名稱,以及測試結果和測試執行持續時間。

Python 主機輸出如下所示:

Python Console
廣告
© . All rights reserved.