這裡記錄了學習 Flutter - Dart 如何進行 Unit test 的方法。
More information: https://flutter.dev/docs/cookbook/testing
-
Basic testing: 一些最基本的語法,expect, contains, start/endsWith 等等
-
Setup testing: 學習怎麼樣在 test 前 setup 一些物件,並在結束時 teardown
-
Asynchronous testing: unit test 最重要的部分,如果搭配 Future, Stream, .. 和不一樣的 emit 與 expect 語法來進行測試
-
以上參考官方所提供的文件
- Adding Dependency
dev_dependencies:
mockito: ^4.0.0
-
Basic Widget testing: 在 testWidget 環境下利用 pumpWidget 生成 widget ,並且使用 find 和 expect 查看是否有此元件
-
Finding widget: Flutter 提供多種方式來查找 widget
-
Interact with widget: 找到 widget 之後,就可以對該 widget 進行 tap, drag, input 等各種測試
- Adding Dependency
dev_dependencies:
flutter_driver:
sdk: flutter
-
在 test_driver 底下建立 test files
-
設定好手機、模擬器,並執行指令
flutter drive --target=test_driver/app.dart