Auto Test Practice
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    1
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 7/15共筆 {%hackmd 1lpg7PuqRoaui6XyJcrylw %} :::info :heart: 這禮拜收到很多好問題!感謝Nickson, Tommy, Jimmy, Delbert, Jim, Sabrina, Mike提問。 ::: ## 目標提醒 ## Function越寫越多,怎麼維護? 維護成本是高的。有人用的東西,才會有維護的價值。所以維護的原則除了讓開發者本身好開發和管理外,另一個原則是要使用者能夠持續的使用。用下列四種類型說明: - Implement Code - Test Cases - Configuration File - 其他(Resource File, Variable File) ### Implement Code 如同使用別人寫好的library/module/package時的做法一樣,身為使用者的我們會想要: - 能夠取得健康的library - 有說明文件參照使用法方法和範例 - 可以根據naming和docstring推敲功能和使用方法 #### 能夠取得健康的library - 做好版本控制 - Branch model - Commit, Push, Merge rules - Review rules - Manual - Automation (e.g. GitLab CI) - Release rules - 參考Git/GitLab/GitHub Flow - [A successful git branching model](https://nvie.com/posts/a-successful-git-branching-model/) - [What are GitLab Flow best practices?](https://about.gitlab.com/topics/version-control/what-are-gitlab-flow-best-practices/) - [Introduction to GitLab Flow](https://docs.gitlab.com/ee/topics/gitlab_flow.html) - [Understanding the GitHub flow](https://guides.github.com/introduction/flow/) > 如果行有餘力的話,針對 Implment Code 做 Unit Test 可以讓 library 更健康 [name=Chuck] #### 有說明文件參照使用法方法和範例 - ==文件也要一起做版本控制== - 參考你常用和相關的library怎麼寫和呈現文件? - [behave API](https://behave.readthedocs.io/en/stable/api.html) - [Robot API](https://robot-framework.readthedocs.io/en/stable/) - [Selenium with Python](https://selenium-python.readthedocs.io/) - [Genie](https://developer.cisco.com/docs/genie-docs/) - 工具 - [Read The Docs](https://docs.readthedocs.io/en/stable/index.html) - [NBG GitLab Wiki](http://mhqnetgitlab.moxa.com/help/user/project/wiki/index.md) #### 可以根據naming和docstring推敲功能和使用方法 - [PEP 8 -- Style Guide for Python Code](https://www.python.org/dev/peps/pep-0008/) - [PEP 257 -- Docstring Conventions](https://www.python.org/dev/peps/pep-0257/) - Function naming convention(參考) - [Genie的functions](https://pubhub.devnetcloud.com/media/genie-feature-browser/docs/#/apis) - 我原本的規則 | Function Name | | ---------------------- | | login | | logout | | reload | | reload_factory_default | | export | | import | | Prefix | Example | | -------- | ------------------- | | add_ | add_static_route | | delete_ | delete_static_route | | enable_ | enable_ospf | | disable_ | disable_ospf | | set_ | set_hostname | | default_ | default_hostname | | get_ | get_system_info | ### Test Cases 同樣以Test Case使用者的角度來看,我會希望: - 可以獲取完整的測項 - 能夠與測試機種和FWR版本對應 - 格式一致 - 能夠看得懂的描述 - 內容有組織 #### 參考==通用==的撰寫規則 - 參考標準化的詞彙和文件架構 - [ISTQB Glossary](https://glossary.istqb.org/en/search/) - [ISO/IEC/IEEE 29119 Software Testing](https://en.wikipedia.org/wiki/ISO/IEC_29119) - ISO/IEC 29119-1: Concepts & definitions - ISO/IEC 29119-3: Test documentation - 用Gherhkin語法組織測試步驟 #### 用工具協助Review和==版本控制== - GitLab - Cucumber(.feature) ![](https://i.imgur.com/Pks2dvf.png) - Robot Framework (.robot) ![](https://i.imgur.com/FtkmTZm.png) ### Configuration file - 會需要有Networking的專業。 - 參考小茂(Cisco, Westermo)怎麼做? - Device - [Set up your testbed file and connect to a device](https://pubhub.devnetcloud.com/media/genie-docs/docs/cookbooks/genie.html#book-setup-testbed) - [Ixia device](https://developer.cisco.com/docs/genie-trafficgen/) - Topology - [Creating Topology](https://pubhub.devnetcloud.com/media/pyats/docs/topology/creation.html#topology-testbed-file) - [Westermo - Automated test mapping and coverage for network topologies](https://www.researchgate.net/publication/326365930_Automated_test_mapping_and_coverage_for_network_topologies) > ![](https://i.imgur.com/0fA4ID0.png) - Testbed - [Describe Your Testbed](https://pubhub.devnetcloud.com/media/pyats/docs/getting_started/index.html#describe-your-testbed) - 參考==通用的==資料格式 - [YAML](http://yaml.org/) ### 其他(Resource File, Variable File) 因為Robot Framework有自己的檔案Resource file, Variable file,所與額外維護。 ![](https://i.imgur.com/crnXRng.png) - 參考Robot Framework Library的文件格式和內容。 - [Build-In](https://robotframework.org/robotframework/latest/libraries/BuiltIn.html) - [Telnet](https://robotframework.org/robotframework/latest/libraries/Telnet.html) - [Selenium](https://robotframework.org/SeleniumLibrary/SeleniumLibrary.html) ## Debug 1. [Install Visual Studio Code and the Python Extension](https://code.visualstudio.com/docs/python/python-tutorial#_install-visual-studio-code-and-the-python-extension) 2. [Initialize debug configurations](https://code.visualstudio.com/docs/python/debugging#_initialize-configurations) 3. 將cucumber和robot的debug configurations加入`launch.json`中`configurations:[]`裡面。 === ```json= "configurations": [ { "name": "behave: Current File Debug", "type": "python", "request": "launch", "module": "behave", "console": "integratedTerminal", "args": [ "-f", "html", "-o", "result/log.html", "-f", "pretty", "${file}" ] }, { "name": "robot: Current File Debug", "type": "python", "request": "launch", "module": "robot", "console": "integratedTerminal", "args": [ "-d", "result", "${file}" ] }, ] ``` 4. 重新開啟VS Code。 5. 設置Config Mode ![](https://i.imgur.com/KfIHk3h.png) 6. 按下`F5`開始Debug。 - 用break point暫停程式。 - 善用watch和debug console來看變數的值。 - ==用`F11`來了解執行的順序== ## Fixture (Setup, Teardown) Fixtures are functions, which will run before or after specific part of test cases. ### In behave (Cucumber) - Syntax - 用`@fixture`裝飾 - 用yield來切分setup和teardown - 配合`try... finally...`來確保發生錯誤時,也會執行tear down。 ```python= from behave import fixture @fixture def open_brower(context): try: context.driver = webdriver.Remote( command_executor = context.remote_webdriver, desired_capabilities = DesiredCapabilities.CHROME) context.driver.implicitly_wait(10) context.wait = WebDriverWait(context.driver, 60) yield context.driver # 用yield來切分setup和teardown的部分 finally: context.driver.quit() ``` - 發動時機 | Context Layer | Fixture-Setup Point | Fixture-Cleanup Point | | ------------- | ---------------------- | ------------------------------------------------------------------ | | test run | In `before_all()` hook | After `after_all()` at end of test-run. | | feature | In `before_feature()` | After `after_feature()`, at end of feature. | | feature | In `before_tag()` | After `after_feature()` for feature tag. | | scenario | In `before_scenario()` | After `after_scenario()`, at end of scenario. | | scenario | In `before_tag()` | After `after_scenario()` for scenario tag. | | scenario | In a step | ==After `after_scenario()`.== Fixture is usable until end of scenario. | :::info :link: [behave fixture](https://behave.readthedocs.io/en/stable/tutorial.html#fixtures) :link: [behave fixture in details](https://behave.readthedocs.io/en/stable/fixtures.html#) ::: ### In Robot Framework - 主要在`.robot`檔案中撰寫。 - Syntax - Test-Suite level ``` *** Settings *** Test Setup Open Application App A Test Teardown Close Application ``` - Test-Case level ``` *** Test Cases *** Using variables [Setup] ${SETUP} Do Something [Teardown] ${TEARDOWN} ``` - Keyword level ``` *** Keywords *** With Teardown Do Something [Teardown] Log keyword teardown ``` - 發動時機為該level開始和結束時執行Setup和Teardown。 :::info :link: [test suite setup and teardwon](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#suite-setup-and-teardown) :link: [test suite setup and teardwon](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#test-setup-and-teardown) :link: [keyword teardown](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#user-keyword-teardown) ::: ## 補充 > Q. Nickson遇到robot的class會反覆開啟instance的問題? > A. Library的Class的Scope要設成Global(這邊的Global指的是在Robot Framework下使用的Scope) > [name=Nickson] > Q. 上述是否可以用singleton改寫?[name=Hilbert] > 參考資料[python 實現 singleton 模式](https://mark1002.github.io/2018/07/31/python-%E5%AF%A6%E7%8F%BE-singleton-%E6%A8%A1%E5%BC%8F/)[name=Chuck] > 因為螢幕投出來的時間很短,我沒有看得很清楚 singleton 是用在什麼地方,或者是不是一定需要用。 雖然 singleton 最大的特色是共用資源,但是同時也是它使用上最需要注意的地方,沒做好資料存取保護,在平行運算的時候就有可能不定期出現資料同時存取的問題(Race Condition),如果讓測試結果偶發性的不穩定,放在這麼核心的地方會非常找 bug。 所以雖然存在這種設計方式,但是會建議在使用前先詳閱公開說明書,再決定是不是要使用。[name=Chuck] > 不管什麼什麼設計模式都有適用或不適用的場合,舉例來說如果團隊合作想要把某種特定測試、但是該測試又想確定資源只被 access / create... 一次,就可以考慮使用 singleton 的設計來 release lib,這樣可以有效的避免使用者誤用造成重複 access 資源而產生不可預期的執行結果、也不需要擔心全域符號覆用 > 沒記錯的話 java instance 就是這樣的設計,但這設計是符合早期瀏覽器使用情境,在現代瀏覽器的使用情境卻造成很多限制。 > 然後 singleton 不是共用資源的目的,目的是找到全宇宙的唯一,共用資源不代表資源只能有一份,但你要指定為一的真愛就可以用 singleton 把它包起來。 [name=Hilbert] >

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully