简体   繁体   English

Flutter 集成测试 - 如何在单个命令或单个文件中运行 Flutter 集成测试的多个测试用例

[英]Flutter Integration Testing- How to run multiple test cases of Flutter integration tests in single command or from single file

How to run multiple test cases of Flutter integration tests in single command or from single file.如何在单个命令或单个文件中运行 Flutter 集成测试的多个测试用例。 1. If I run two separate commands for two files then report generates only for last command. 1. 如果我为两个文件运行两个单独的命令,则报告只为最后一个命令生成。 2. When I try to do separate groups in single file then app stays on same page doesn't restart. 2.当我尝试在单个文件中进行单独的组时,应用程序停留在同一页面上不会重新启动。

Here I need to restart app for further processing.在这里,我需要重新启动应用程序以进行进一步处理。 Is there any way to combine multiple test cases to run from multiple files.?有没有办法将多个测试用例组合起来从多个文件运行。?

Thing to consider: I am using ozzie as a report generator.要考虑的事情:我使用 ozzie 作为报告生成器。

Thanks in advance.提前致谢。

You may trying to run all test-case from one file.您可能会尝试从一个文件运行所有测试用例。 it may help, though its late replay.尽管重播较晚,但它可能会有所帮助。

Suppose you have 3 test file which is,假设您有 3 个测试文件,即

  1. login.dart and login_test.dart (where all the test-case has to be written in login_test.dart ) login.dart 和 login_test.dart (所有测试用例都必须写在login_test.dart中)
  2. register.dart and register_test.dart register.dart 和 register_test.dart
  3. forgotPassword.dart and forgotPassword_test.dart forgotPassword.dart 和 forgotPassword_test.dart

Put all those test-cases into a main function.将所有这些测试用例放入主 function。 (describing only one test file code [login_test.dart] ) (仅描述一个测试文件代码[login_test.dart]

main(){
  loginTest();

}
Future<void> loginTest()async{

  group('Login Page Automation Test :', () {

//Write your test-cases here

}

so, now create a test file and call all the main functions on that file, which will be used to run all cases at once.所以,现在创建一个测试文件并调用该文件上的所有主要函数,这将用于一次运行所有案例。

testAll.dart & testAll_test.dart

Write in these format on testAll_test.dart以这些格式写在 testAll_test.dart

import 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart';


import 'login_test.dart';
import 'register_test.dart';
import 'forgotPassword_test.dart';



main() {
  testAll();
}

Future<void> testAll() async {
  group('All TestCase at Once: ', () {

    //code here

    FlutterDriver driver;
    // Connect to the Flutter driver before running any tests.
    setUpAll(() async {
      driver = await FlutterDriver.connect();
    });

    // Close the connection to the driver after the tests have completed.
    tearDownAll(() async {
      if (driver != null) {
        driver.close();
      }
    });

    //main methods below

    forgotPasswordTest();

    registerTest();

    loginTest();


  });
}

and finally run the app using this.最后使用它运行应用程序。

flutter drive --target=test_driver/testAll.dart

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

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