Last active
August 11, 2023 11:42
-
-
Save bartekpacia/b6f6bca8d1a09966a2ce99fb065a3070 to your computer and use it in GitHub Desktop.
Nested groups and test cases example.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DartTestGroup { | |
String name = ''; | |
List<DartTestCase> tests = []; | |
List<DartTestGroup> groups = []; | |
DartTestGroup({ | |
required this.name, | |
this.tests = const [], | |
this.groups = const [], | |
}); | |
} | |
class DartTestCase { | |
String name = '';s | |
DartTestCase({ | |
required this.name, | |
}); | |
} | |
void main() { | |
DartTestGroup topGroup = DartTestGroup( | |
name: 'top', | |
groups: [ | |
DartTestGroup( | |
name: 'example_test.dart', | |
tests: [ | |
DartTestCase(name: 'direct descendant 1'), | |
DartTestCase(name: 'direct descendant 2'), | |
], | |
groups: [ | |
DartTestGroup( | |
name: 'dummy tests', | |
tests: [ | |
DartTestCase(name: 'dummy test 1'), | |
DartTestCase(name: 'dummy test 2'), | |
], | |
), | |
DartTestGroup( | |
name: 'maps apps', | |
tests: [ | |
DartTestCase(name: 'run Google maps'), | |
DartTestCase(name: 'run Waze maps'), | |
], | |
), | |
], | |
), | |
], | |
); | |
printGroupStructure(topGroup, 0); | |
} | |
void printGroupStructure(DartTestGroup group, int indentation) { | |
String indent = ' ' * indentation; | |
print('$indent-- group: \'${group.name}\''); | |
for (var testCase in group.tests) { | |
print('$indent -- test: \'${testCase.name}\''); | |
} | |
for (var subgroup in group.groups) { | |
printGroupStructure(subgroup, indentation + 5); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment