Skip to content

Commit 7b2f25a

Browse files
authored
feat(test): add --test-randomize-ordering-seed (VeryGoodOpenSource#326)
1 parent 7d5699b commit 7b2f25a

File tree

3 files changed

+72
-16
lines changed

3 files changed

+72
-16
lines changed

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,15 @@ very_good test -r
161161
Run tests in a Dart or Flutter project.
162162

163163
Usage: very_good test [arguments]
164-
-h, --help Print this usage information.
165-
--coverage Whether to collect coverage information.
166-
-r, --recursive Run tests recursively for all nested packages.
167-
--[no-]optimization Whether to apply optimizations for test performance.
168-
(defaults to on)
169-
--exclude-coverage A glob which will be used to exclude files that match from the coverage.
170-
-x, --exclude-tags Run only tests that do not have the specified tags.
171-
--min-coverage Whether to enforce a minimum coverage percentage.
164+
-h, --help Print this usage information.
165+
--coverage Whether to collect coverage information.
166+
-r, --recursive Run tests recursively for all nested packages.
167+
--[no-]optimization Whether to apply optimizations for test performance.
168+
(defaults to on)
169+
--exclude-coverage A glob which will be used to exclude files that match from the coverage.
170+
-x, --exclude-tags Run only tests that do not have the specified tags.
171+
--min-coverage Whether to enforce a minimum coverage percentage.
172+
--test-randomize-ordering-seed The seed to randomize the execution order of test cases within test files.
172173

173174
Run "very_good help" to see global options.
174175
```

lib/src/commands/test/test.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ class TestCommand extends Command<int> {
6565
..addOption(
6666
'min-coverage',
6767
help: 'Whether to enforce a minimum coverage percentage.',
68+
)
69+
..addOption(
70+
'test-randomize-ordering-seed',
71+
help: 'The seed to randomize the execution order of test cases '
72+
'within test files.',
6873
);
6974
}
7075

@@ -106,6 +111,8 @@ This command should be run from the root of your Flutter project.''',
106111
final excludeTags = _argResults['exclude-tags'] as String?;
107112
final isFlutterInstalled = await _flutterInstalled();
108113
final excludeFromCoverage = _argResults['exclude-coverage'] as String?;
114+
final randomOrderingSeed =
115+
_argResults['test-randomize-ordering-seed'] as String?;
109116
final optimizePerformance = _argResults['optimization'] as bool;
110117

111118
if (isFlutterInstalled) {
@@ -121,6 +128,10 @@ This command should be run from the root of your Flutter project.''',
121128
excludeFromCoverage: excludeFromCoverage,
122129
arguments: [
123130
if (excludeTags != null) ...['-x', excludeTags],
131+
if (randomOrderingSeed != null) ...[
132+
'--test-randomize-ordering-seed',
133+
randomOrderingSeed
134+
],
124135
'--no-pub',
125136
..._argResults.rest,
126137
],

test/src/commands/test/test_test.dart

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ const expectedTestUsage = [
1414
'Run tests in a Dart or Flutter project.\n'
1515
'\n'
1616
'Usage: very_good test [arguments]\n'
17-
'-h, --help Print this usage information.\n'
18-
' --coverage Whether to collect coverage information.\n'
19-
'''-r, --recursive Run tests recursively for all nested packages.\n'''
20-
''' --[no-]optimization Whether to apply optimizations for test performance.\n'''
21-
' (defaults to on)\n'
22-
''' --exclude-coverage A glob which will be used to exclude files that match from the coverage.\n'''
23-
'''-x, --exclude-tags Run only tests that do not have the specified tags.\n'''
24-
''' --min-coverage Whether to enforce a minimum coverage percentage.\n'''
17+
'-h, --help Print this usage information.\n'
18+
''' --coverage Whether to collect coverage information.\n'''
19+
'''-r, --recursive Run tests recursively for all nested packages.\n'''
20+
''' --[no-]optimization Whether to apply optimizations for test performance.\n'''
21+
' (defaults to on)\n'
22+
''' --exclude-coverage A glob which will be used to exclude files that match from the coverage.\n'''
23+
'''-x, --exclude-tags Run only tests that do not have the specified tags.\n'''
24+
''' --min-coverage Whether to enforce a minimum coverage percentage.\n'''
25+
''' --test-randomize-ordering-seed The seed to randomize the execution order of test cases within test files.\n'''
2526
'\n'
2627
'Run "very_good help" to see global options.'
2728
];
@@ -177,6 +178,49 @@ void main() {
177178
).called(1);
178179
});
179180

181+
test('completes normally --test-randomize-ordering-seed random', () async {
182+
when<dynamic>(
183+
() => argResults['test-randomize-ordering-seed'],
184+
).thenReturn('random');
185+
final result = await testCommand.run();
186+
expect(result, equals(ExitCode.success.code));
187+
verify(
188+
() => flutterTest(
189+
arguments: [
190+
'--test-randomize-ordering-seed',
191+
'random',
192+
...defaultArguments
193+
],
194+
optimizePerformance: true,
195+
progress: logger.progress,
196+
stdout: logger.write,
197+
stderr: logger.err,
198+
),
199+
).called(1);
200+
});
201+
202+
test('completes normally --test-randomize-ordering-seed 2305182648',
203+
() async {
204+
when<dynamic>(
205+
() => argResults['test-randomize-ordering-seed'],
206+
).thenReturn('2305182648');
207+
final result = await testCommand.run();
208+
expect(result, equals(ExitCode.success.code));
209+
verify(
210+
() => flutterTest(
211+
arguments: [
212+
'--test-randomize-ordering-seed',
213+
'2305182648',
214+
...defaultArguments
215+
],
216+
optimizePerformance: true,
217+
progress: logger.progress,
218+
stdout: logger.write,
219+
stderr: logger.err,
220+
),
221+
).called(1);
222+
});
223+
180224
test('completes normally --coverage', () async {
181225
when<dynamic>(() => argResults['coverage']).thenReturn(true);
182226
final result = await testCommand.run();

0 commit comments

Comments
 (0)