Can I run multiple integration tests with one single config file in Flutter?

我怕爱的太早我们不能终老 提交于 2019-12-10 15:18:04

问题


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?

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.

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();
}

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...
});
});

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?


回答1:


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

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.

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

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




回答2:


You can always have one main test file that you initiate, like say

flutter drive --target=test_driver/app_test.dart

Then in that call your test groups as functions, like so -

void main() {
  test1();
}
void test1() {
  group('test 1', () {});}

So with one command you get to execute all the cases mentioned in the main()



来源:https://stackoverflow.com/questions/56236606/can-i-run-multiple-integration-tests-with-one-single-config-file-in-flutter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!