【问题标题】:Conditionally Execute test() in Flutter在 Flutter 中有条件地执行 test()
【发布时间】:2020-02-11 14:19:09
【问题描述】:

当使用 Flutter testdrive 选项时,我们可以根据之前的结果来控制某些测试的执行吗?我们在测试中有一个skip 选项。但是,无论如何我都无法检查程序中是否通过了先前的测试。例如:

    void main() {
      group('Group A', () {
        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();
          }
        });

        test('Test A', () async {
        });

        test('Test B', () async {
        });

        test('Test C', () async {
        });
      });
        }

我的问题是,如果 A 失败,我该如何跳过 B 和 C 的执行?如何跳过 group B id group A 测试失败的执行?

【问题讨论】:

    标签: flutter dart flutter-dependencies flutter-test


    【解决方案1】:

    似乎没有明确的方式来声明测试依赖项,但您可以跟踪哪些测试已通过,并使用该信息有条件地跳过后续测试,例如

    final passed = <String>{};
    
    test("a", () {
      expect(1 + 1, 3);
      passed.add("a");
    });
    
    test("b", () {
      expect(2 + 2, 5);
    }, skip: !passed.containsAll(["a"]));
    

    【讨论】:

    • 请注意,这可以工作并跳过测试,但令人困惑的是,它仍然会在调试器控制台中打印测试名称和打勾
    猜你喜欢
    • 1970-01-01
    • 2013-02-03
    • 1970-01-01
    • 1970-01-01
    • 2012-11-12
    • 2018-07-25
    • 1970-01-01
    • 2013-12-27
    • 2017-02-20
    相关资源
    最近更新 更多