我可以在 Flutter 中使用一个配置文件运行多个集成测试吗? [英] Can I run multiple integration tests with one single config file in Flutter?

查看:18
本文介绍了我可以在 Flutter 中使用一个配置文件运行多个集成测试吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写 Flutter 集成测试并使用一个配置文件来运行它们,而不是为每个测试都制作配置文件.有没有办法做到这一点?

I am trying to write Flutter integration tests and to run them all with one config file instead of making config file for every single test. Is there any way to do that?

现在我有 login.dart 和 login_test.dart 等等,用于每一个测试.我知道每个配置和测试文件必须具有相同名称的约定,但这不是我需要的,欢迎更多可配置的东西.提前致谢.

For now I have login.dart and login_test.dart and so on, for every single test. I know its convention that every config and test file must have the same name, but that's not what I need, more configurable things are welcomed. Thanks in advance.

这是我的配置文件(login.dart)

This is my config file (login.dart)

import 'package:flutter_driver/driver_extension.dart';
import 'package:seve/main.dart' as app;

void main() {
enableFlutterDriverExtension();
app.main();
}

测试(login_test.dart)看起来像这样

And test (login_test.dart) looks something like this

import ...

FlutterDriver driver;

void main() {

setUpAll(() async {
driver = await FlutterDriver.connect();
});

tearDownAll(() async {
if (driver != null) {
  driver.close();
}
});

test('T001loginAsDriverAndVerifyThatDriverIsLogedInTest', () async {
  some_code...
});
});

现在我想制作新的测试文件(例如 login_warning.dart)并能够通过调用单个配置文件(login.dart)来启动两个测试.这可能吗?

Now I want to make new test file (e.g login_warning.dart) and be able to start both tests by calling single config file (login.dart). Is that even possible?

推荐答案

是的,可以使用相同的配置"运行多个测试"文件.

Yes, running multiple "test" files with the same "config" is possible.

用颤振的术语来说,你的配置文件是你的目标,你的测试文件是你的驱动程序.您的目标始终是 login.dart 但您有两个驱动程序 login_test.dartlogin_warning.dart.

In the flutter jargon, your config file is your target and your test file is your driver. Your target is always login.dart but you have the two drivers login_test.dart and login_warning.dart.

使用 flutter drive 命令,您可以指定 target 以及 driver.

With the flutter drive command, you can specify the target as well as the driver.

因此,为了运行这两个驱动程序,只需执行以下命令

So in order to run both drivers, simply execute the following commands

flutter drive --target=test_driver/login.dart --driver=test_driver/login_test.dart
flutter drive --target=test_driver/login.dart --driver=test_driver/login_warning.dart

这将首先执行 login_test.dart,然后执行 login_warning.dart 驱动程序.

This executes first the login_test.dart and then the login_warning.dart driver.

这篇关于我可以在 Flutter 中使用一个配置文件运行多个集成测试吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆