了解剛出爐的 Honey E2E Testing,不是開發者也能幫忙寫 Flutter 測試!

Yii Chen
Flutter Formosa
Published in
7 min readJan 7, 2023

新的 HoneyTalk 測試語言

Honey 是一個很棒的套件,出了之後就持續在關注它,感覺對開發者來說非常簡單,也對非工程人員很有幫助,只需透過平凡口語的句子來撰寫測試,驗證使用者最常操作的流程與場景,讓我們的 APP 品質更有保障。趕緊來玩看看吧~

Introduction

  • E2E Test framework
  • 作者為 ClickUp 的開發人員,知名開源者
  • 使用 HoneyTalk 語言搭配句子來撰寫測試,即便不是工程師也能參與,完全不需要了解實作細節
  • 默認為非同步,不需要額外等待耗時操作和動畫
  • 提供 accessibility trees,查看每個元件的可視資訊,包含屬性、位置、大小
  • 夥伴產品有 Hive、Isar 等套件

Installation

dependencies:
...
honey: <latest-version>

Setup

main() 方法透過環境變數去判斷是否要執行 Honey 初始化,使用 HoneyWidgetsBinding

launch.json of VSCode
void main() {
const kIsHoney = bool.fromEnvironment('HONEY');
if (kIsHoney) {
HoneyWidgetsBinding.ensureInitialized();
}

runApp(const MyApp());
}

Write Test

在根目錄新建一個 honey 資料夾,每個測試檔的副檔名為 .honey

檢查文字

  1. see
  2. expect that
  3. verify that
  4. make sure that
  5. assert that
  6. look that

點擊按鈕

  1. tap
  2. click
  3. hit

輸入文字

  1. enter
  2. type

滑動

  1. swipe
  2. slide
  3. scroll
swipe left "list" by 100

呼叫方法

autoLogin()

tap "Action" button
verify "New note" is visible

more..

條件判斷

if "button" is visible then
print "hello"
else
print "world"
endif

本文範例提供了兩個頁面,我們撰寫自定義測試流程,主頁面為原本的計數器,第二頁顯示一些文字

verify that "0" is visible

tap "Increment" button

verify that "1" is visible

click "Increment" button

make sure that "2" is visible
expect that "3" is not visible

click "Second" button

expect that "Second" is visible
expect that "Hello world" is visible

Run

VSCode Configuration

VSCode Extension

安裝 VSCode 套件,搜尋 Honey,支援 HoneyTalk language 的撰寫,協助點亮所使用的關鍵字

Demo

App running
Check details of widget
Test info

Weakness

  • 剛開始釋出不久,文件還不完整
  • 撰寫測試的前提,需要有英文對話的能力,文法正確才能寫好測試

Source Code

--

--

Flutter Formosa
Flutter Formosa

Published in Flutter Formosa

Flutter lovers make Chinese community strong.

Yii Chen
Yii Chen

Written by Yii Chen

Flutter Lover || Organizer FlutterTaipei || Writer, Speaker || wanna make Flutter strong in Taiwan. https://linktr.ee/yiichenhi