Reputation: 1526
When using the Flutter test
and drive
options, can we control the execution of certain test based on the results from the previous ones ? We have a skip
option in the test. However, I was unable to find anyway to check whether a previous test passed in the program. For example :
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 {
});
});
}
My question is , how can I skip the execution of B and C if A failed and how can I skip the execution of group B id group A tests failed ?
Upvotes: 2
Views: 1823
Reputation: 3614
There doesn't appear to be an explicit way to declare test dependencies, but you could keep track of which tests have passed, and use that information to skip subsequent tests conditionally, e.g.
final passed = <String>{};
test("a", () {
expect(1 + 1, 3);
passed.add("a");
});
test("b", () {
expect(2 + 2, 5);
}, skip: !passed.containsAll(["a"]));
Upvotes: 3