首页 > 解决方案 > 从 Flutter_driver 迁移到 integration_test 包

问题描述

我正在从flutter_driver迁移到integration_test包,因为这个页面表明:https ://flutter.dev/docs/testing/integration-tests

但是我发现使用 integration_test 包( https://github.com/flutter/flutter/tree/master/packages/integration_test#integration_test )编写测试的过程非常缓慢。

我最初使用 flutter_driver 做的是在 VSCode 中有一个 .vscode\launch.json 中的文件,其中包含以下配置:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Integration Tests: Launch App",
            "request": "launch",
            "type": "dart",
            "program": "test_driver/app.dart",
            "args": [
                "--flavor",
                "dev"
            ]
        },
        {
            "name": "Integration Tests: Launch Driver",
            "request": "launch",
            "type": "dart",
            "program": "test_driver/test/profile_test.dart",
            "env": {
                "VM_SERVICE_URL": "http://127.0.0.1:63189/wlwt0cVPix4=/#/vm"
              },
        }

    ]
}

我以前先运行 "Integration Tests: Launch App" ,然后复制 "127.0.0.1:54315/5YvmessTCI0="

从调试控制台:

√  Built build\app\outputs\flutter-apk\app-debug.apk.
Connecting to VM Service at ws://127.0.0.1:54315/5YvmessTCI0=/ws

然后将其粘贴到 launch.json 文件的“env”对象“集成测试:启动驱动程序”配置中

之后,我只是在“集成测试:启动驱动程序”配置的“程序”对象中添加了我想调试的测试的名称。

最后,我曾经在“集成测试:启动应用程序”运行时运行“集成测试:启动驱动程序”。

这使我可以在继续运行测试的同时保持应用程序运行,而无需每次都构建 APK。它很快,因为只需要几秒钟即可运行 flutter_driver 步骤,这样您就可以查看您的步骤是否按预期工作。我还可以添加断点并调试我的测试。

问题是在迁移到 integration_test 包后,我无法实现这一点。每次我在测试中添加一个新步骤并且我想确保它按预期工作时,我都必须每次都构建 APK,这非常耗时。

将此配置添加到 launch.json :

        {
            "name": "Integration Test: Run Test",
            "program": "integration_test/app_test.dart",
            "request": "launch",
            "type": "dart"
        },

运行“集成测试:运行测试”可用于添加断点并运行测试。但是如果我在一个步骤中进行了更改,并且我想查看它是否按预期运行,我需要再次运行它,并且构建它需要很多时间。

有没有办法像我对 flutter_driver 那样调试 integration_test 包测试?目标是让应用程序运行并能够运行 integration_test 包测试,而不必每次都构建 APK,就像我们过去使用 flutter_driver 测试所做的那样

标签: flutterflutter-testflutterdriverflutter-integration-test

解决方案


推荐阅读