gpt4 book ai didi

flutter - 在Flutter中有条件地执行test()

转载 作者:行者123 更新时间:2023-12-03 03:16:06 25 4
gpt4 key购买 nike

当使用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的执行?如何跳过B组ID的执行?A组测试失败?

最佳答案

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

final passed = <String>{};

test("a", () {
expect(1 + 1, 3);
passed.add("a");
});

test("b", () {
expect(2 + 2, 5);
}, skip: !passed.containsAll(["a"]));

关于flutter - 在Flutter中有条件地执行test(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58385557/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com