返回介绍

Testing Flutter apps

发布于 2019-12-09 21:31:24 字数 6255 浏览 880 评论 0 收藏 0

  • Widget tests
  • Integration tests
  • Continuous integration services
  • The more features your app has, the harder it is to test manually. Automated tests help ensure that your app performs correctly before you publish it, while retaining your feature and bug fix velocity.

    Automated testing falls into a few categories:

    • A unit test tests a single function, method, or class.
    • A widget test (in other UI frameworks referred to as component test) tests a single widget.
    • An integration test tests a complete app or a large part of an app.

    Generally speaking, a well-tested app has many unit and widget tests, tracked by code coverage, plus enough integration tests to cover all the important use cases. This advice is based on the fact that there are trade-offs between different kinds of testing, seen below.

     UnitWidgetIntegration
    ConfidenceLowHigherHighest
    Maintenance costLowHigherHighest
    DependenciesFewMoreMost
    Execution speedQuickSlowerSlowest

    Unit tests

    A unit test tests a single function, method, or class. The goal of a unit test is to verify the correctness of a unit of logic under a variety of conditions. External dependencies of the unit under test are generally mocked out. Unit tests generally don’t read from or write to disk, render to screen, or receive user actions from outside the process running the test.

    Recipes

    Widget tests

    A widget test (in other UI frameworks referred to as component test) tests a single widget. The goal of a widget test is to verify that the widget’s UI looks and interacts as expected. Testing a widget involves multiple classes and requires a test environment that provides the appropriate widget lifecycle context.

    For example, the Widget being tested should be able to receive and respond to user actions and events, perform layout, and instantiate child widgets. A widget test is therefore more comprehensive than a unit test. However, like a unit test, a widget test’s environment is replaced with an implementation much simpler than a full-blown UI system.

    Recipes

    Integration tests

    An integration test tests a complete app or a large part of an app. The goal of an integration test is to verify that all the widgets and services being tested work together other as expected. Furthermore, you can use integration tests to verify your app’s performance.

    Generally, an integration test runs on a real device or an OS emulator, such as iOS Simulator or Android Emulator. The app under test is typically isolated from the test driver code to avoid skewing the results.

    Recipes

    Continuous integration services

    Continuous integration (CI) services allow you to run your tests automatically when pushing new code changes. This provides timely feedback on whether the code changes work as expected and do not introduce bugs.

    For information on running tests on various continuous integration services, please see the following:

    如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

    扫码二维码加入Web技术交流群

    发布评论

    需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
    列表为空,暂无数据
      我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
      原文