|
| 1 | +import 'package:meta/meta.dart'; |
| 2 | +import 'package:test/test.dart'; |
| 3 | + |
| 4 | +import '../parameterized_test.dart'; |
| 5 | +import 'test_options/group_test_options.dart'; |
| 6 | +import 'value_source.dart'; |
| 7 | + |
| 8 | +/// Create a new parameterizedGroup with given [description], [values] and [body] |
| 9 | +/// |
| 10 | +/// [parameterizedGroup] also have the same options as group tests have. These options will be passed to the group function. |
| 11 | +/// |
| 12 | +/// For example: |
| 13 | +/// ```dart |
| 14 | +/// parameterizedGroup( |
| 15 | +/// 'Amount of letters', |
| 16 | +/// [ |
| 17 | +/// ['kiwi', 4], |
| 18 | +/// ['apple', 5], |
| 19 | +/// ['banana', 6].withTestOptions(skip: 'skip this'), |
| 20 | +/// ], |
| 21 | +/// p2((String word, int length) { |
| 22 | +/// test('test word length',() { |
| 23 | +/// expect(word.length, length); |
| 24 | +/// }); |
| 25 | +/// }), |
| 26 | +/// ); |
| 27 | +/// ``` |
| 28 | +@isTestGroup |
| 29 | +void parameterizedGroup( |
| 30 | + /// Group description. |
| 31 | + Object description, |
| 32 | + |
| 33 | + /// List of group values. For each values in the list a group test will be executed. |
| 34 | + Iterable<dynamic> values, |
| 35 | + |
| 36 | + /// The test body which is executed for each group value. |
| 37 | + /// See [TestParameters] for more info on different bodies. |
| 38 | + TestParameters body, { |
| 39 | + dynamic Function()? setUp, |
| 40 | + |
| 41 | + /// Provide a tearDown function to the `group` test. |
| 42 | + dynamic Function()? tearDown, |
| 43 | + String? testOn, |
| 44 | + Timeout? timeout, |
| 45 | + dynamic skip, |
| 46 | + dynamic tags, |
| 47 | + Map<String, dynamic>? onPlatform, |
| 48 | + int? retry, |
| 49 | +}) { |
| 50 | + ValueSource( |
| 51 | + values, |
| 52 | + GroupTestOptions( |
| 53 | + description: description, |
| 54 | + setUp: setUp, |
| 55 | + tearDown: tearDown, |
| 56 | + testOn: testOn, |
| 57 | + timeout: timeout, |
| 58 | + skip: skip, |
| 59 | + tags: tags, |
| 60 | + onPlatform: onPlatform, |
| 61 | + retry: retry, |
| 62 | + ), |
| 63 | + ).executeGroup(body); |
| 64 | +} |
0 commit comments