简体   繁体   English

如何在Flutter中进行集成测试?

[英]How to do integration testing in Flutter?

I want to do integration testing in Flutter. 我想在Flutter中进行集成测试。 The tutorial I follow gives the following procedure: 我遵循的教程提供了以下过程:

  1. Add the flutter_driver package to pubspec: 将flutter_driver包添加到pubspec:
dev_dependencies:
flutter_driver:
sdk: flutter
  1. Enable the Flutter driver extension and add a call to the enableFlutterDriverExtension() function in main.dart. 启用Flutter驱动程序扩展并添加对main.dart中enableFlutterDriverExtension()函数的调用。
  2. Run the integration test by using the flutter drive command: flutter drive --target=my_app/test_driver/my_test.dart 使用flutter drive命令运行集成测试:flutter drive --target = my_app / test_driver / my_test.dart

My problem is with understanding step 2. It's not clear to me where in Android Studio do you enable the driver extension and where exactly in main.dart do you call the function enableFlutterDriveExtension(). 我的问题在于理解第2步。我不清楚在Android Studio中你在哪里启用驱动程序扩展,在main.dart中你究竟在哪里调用函数enableFlutterDriveExtension()。

I also have problems with the third step. 第三步我也有问题。 After running the said command, it says in my terminal that 运行上述命令后,它在我的终端中说

Error: The Flutter directory is not a clone of the GitHub project.
       The flutter tool requires Git in order to operate properly;
       to set up Flutter, run the following command:
       git clone -b stable https://github.com/flutter/flutter.git

You have to add this code inside the test_driver/app.dart file. 您必须在test_driver / app.dart文件中添加此代码。

import 'package:flutter_driver/driver_extension.dart';
import 'package:[YOUR_APP]/main.dart' as app;

void main() {
  // This line enables the extension
  enableFlutterDriverExtension();

  // Call the `main()` function of your app or call `runApp` with any widget you
  // are interested in testing.
  app.main();
}

You can find more info on the official Flutter documentation site (Steps 3 & 4): https://flutter.dev/docs/cookbook/testing/integration/introduction 您可以在官方Flutter文档站点上找到更多信息(步骤3和4): https//flutter.dev/docs/cookbook/testing/integration/introduction

Good luck ;) 祝好运 ;)

In order to run integration test in flutter, you need to create "test_driver" directory inside app root dir. 为了在flutter中运行集成测试,您需要在app root dir中创建“test_driver”目录。 Than you need to create two files inside "test_driver" folder. 比你需要在“test_driver”文件夹中创建两个文件。

  1. Lets call first file "app.dart" and there you need to instrument your app(answer above). 让我们调用第一个文件“app.dart”,你需要检测你的应用程序(上面的答案)。
  2. Than you need to create your test file, which needs to be called "app_test.dart" and here you write your actual test code. 您需要创建测试文件,需要将其命名为“app_test.dart”,然后在此处编写实际的测试代码。
  3. When you want to run that test, just run "flutter drive --target=test_driver/app.dart". 如果要运行该测试,只需运行“flutter drive --target = test_driver / app.dart”。

    About step 3 in your question, check if you set flutter home properly and after adding flutter_driver dependency, run "packages get". 关于问题中的第3步,检查是否正确设置了flutter home,并在添加flutter_driver依赖项后,运行“packages get”。

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

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