yii.
← Writing
Flutter 技術 · · 4 min read · 閱讀中文版

Honey E2E Testing in Flutter. This honey is good to eat and sweet.

這篇寫於 2023 年。工具和 API 變化很快,部分步驟可能已經不適用。

New HoneyTalk language for testing

Honey is a great package. I have been paying attention to it since it was released. I tried it out recently. I feel that it is very simple for developers, and it is also very helpful for non-engineers. It only needs to be written through ordinary spoken sentences Test and verify the processes and scenarios most frequently operated by users, so that the quality of our APP is more guaranteed. Come and play now~


Introduction#

  • E2E Test framework
  • The author is the developer of ClickUp, a well-known open-source contributor
  • Use HoneyTalk language with sentences to write tests, even non-engineers can participate, no need to understand implementation details
  • The default is asynchronous, no need to wait for time-consuming operations and animations
  • Provide Accessibility Tree to view the visual information of each component, including attributes, positions, and sizes
  • Other works are Hive, Isar, and other suites

honey | Flutter PackageHoney is an end-to-end test framework for Flutter apps. It is designed to be really easy to set up and use. The…pub.dev

Installation#

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

Setup#

In the main() method, use environment variables to determine whether to execute Honey initialization, using HoneyWidgetsBinding.

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

  runApp(const MyApp());
}

Write Test#

Create a new honey folder in the root directory, and the extension of each test file is named .honey

Verify Text#

  1. see
  2. expect that
  3. verify that
  4. make sure that
  5. assert that
  6. look that
verify that "0" is visible

Tap Button#

  1. tap
  2. click
  3. hit

Input Text#

  1. enter
  2. type

Swipe#

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

Call Functions#

autoLogin()

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

more..

Conditions#

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

The example of this article provides two pages. We write a custom test process. The main page is the original counter, and the second page displays some text.

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

honey/honeytalk.md at main · clickup/honeyHoney tests are written in a natural test language called “HoneyTalk” which looks like English. There are many built-in…github.com

Run#

VSCode Configuration

VSCode Extension#

Install the VSCode plugin, search the keyword Honey, support the writing of HoneyTalk language, and help highlight the keywords used.

Demo#

App running
App running
Check details of widget
Check details of widget
Test info
Test info

Weakness#

  • Not long after it was released, the documents were not complete
  • The premise of writing a test requires the ability to communicate in English, and the grammar is correct to write a good test

Source Code#

GitHub — chyiiiiiiiiiiii/honey_test_example: Honey is a handy tool for people to run E2E tests on…Honey e2e testing is an awesome package. After I tried it for a while, I feel it was so easy and helpful for…github.com


About#

Contribute#

Thank you for taking the time to read it. If you feel good, you can donate. It will give me more motivation and enthusiasm to share more interesting content! Buy me a cup of coffee~

https://www.buymeacoffee.com/yiichenhi

End#

Follow me to get the latest articles.

本文原刊登於 Medium。