简体   繁体   English

什么是小部件测试?

[英]What is widget testing?

I just started with testing in flutter i am writing unit tests for my business logic.我刚开始在 flutter 中进行测试,我正在为我的业务逻辑编写单元测试。 I am also familiar with mocking dependencies, however widget testing is quite overwhelming?我也熟悉 mocking 依赖项,但是小部件测试是相当压倒性的? In Widget testing what are we actually doing?在小部件测试中,我们实际上在做什么? Can someone answer this with a simple analogy有人可以用一个简单的类比来回答这个问题吗

In Flutter I'd outline:在 Flutter 我会概述:

  1. Unit testing via https://pub.dev/packages/test - Dart's standard unit testing package.通过https://pub.dev/packages/test进行单元测试- Dart 的标准单元测试 package。 It knows nothing about Flutter and Widgets.它对 Flutter 和小部件一无所知。 You create tests, where class instances are initialized, methods are called, instances' state is checked - a typical unit testing irrelevant to UI framework.您创建测试,在其中初始化 class 实例,调用方法,检查实例的 state - 与 UI 框架无关的典型单元测试。 Sounds like what you're doing.听起来像你在做什么。
  2. Widget testing with https://api.flutter.dev/flutter/flutter_test/flutter_test-library.html - Flutters widget testing library, depebds on Dart's test.使用https://api.flutter.dev/flutter/flutter_test/flutter_test-library.html进行小部件测试- 飞镖小部件测试库上的颤振小部件测试库。 This one is used to emulate Flutter engine (ie creating MaterialApp, Widgets etc.) and iteract with virtual UI (or part of UI) of your app by clicking buttons, waiting for animations to complete and UI to refresh (via tester.pump()) etc. It is called Widget testing cause you essential test specific Widgets of your app, rather than some generic 'units' of code.这个用于模拟 Flutter 引擎(即创建 MaterialApp、Widget 等)并通过单击按钮与应用程序的虚拟 UI(或 UI 的一部分)进行迭代,等待动画完成和 UI 刷新(通过 tester.pump( )) 等等。它被称为小部件测试,因为您必须测试应用程序的特定小部件,而不是一些通用的代码“单元”。
  3. UI/Integration testing via https://api.flutter.dev/flutter/flutter_driver/flutter_driver-library.html - Flutter's analog to Selenium Web Driver, runs tests against a complete app running in emulator or on physycal device. UI/Integration testing via https://api.flutter.dev/flutter/flutter_driver/flutter_driver-library.html - Flutter's analog to Selenium Web Driver, runs tests against a complete app running in emulator or on physycal device.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM