# 6/10 共筆 {%hackmd 1lpg7PuqRoaui6XyJcrylw %} ## Directories - features/ - `xxx.feature` (for pm...看,不需要知道import什麼code) - `environment.py` - steps/ (放置implement code) - `xxx.py` - `xxx.py` ## Test Cases -- Feature Files ```gherkin= Feature: 功能名稱/Requirements Requirements說明 Scenario: 測試情境 Senario說明 Given ... And ... When ... But ... Then ... Scenario Outline: 測項大綱名稱 Given ... <thing> ... When ... Then ... <other thing> ... Examples: 資料名稱1 | thing | other thing | | Red Tree Frog | mush | Examples: 資料名稱2 | thing | other thing | | iPhone | toxic waste | | Galaxy Nexus | toxic waste | Scenario: ... Given a sample text loaded into the frobulator """ .............. ....一段文字.... .............. """ When ... Then ... Scenario: ... Given a set of specific users | name | department | | Barry | Beer Cans | | Pudey | Silly Walks | | Two-Lumps | Silly Walks | When ... Then ... But ... ``` ## Implement Codes -- Steps File - argument `context` - steps - decorators: `@given` `@when` `@then` - parameters: `@given('...{para}...')` - step status - fail: use `assert` `raise` `except` - environment.py - `before_step(context, step)` - `after_step(context, step)` - `before_scenario(context, scenario)` - `after_scenario(context, scenario)` - `before_feature(context, feature)` - `after_feature(context, feature)` - `before_tag(context, tag)` - `after_tag(context, tag)` - `before_all(context)` - `after_all(context)` ![](https://i.imgur.com/0NF8inj.jpg) 一次只能讀一個table ![](https://i.imgur.com/h7EdVKI.png) - context - 全域 - ![](https://i.imgur.com/PyWcepc.png) - behave 指令參數 - --tags="@a and @b" - @a or @b - not @a - -o 輸出後的檔案名稱 - -f format