group method

void group(
  1. String name,
  2. void body(), {
  3. String? testOn,
  4. Timeout? timeout,
  5. Object? skip,
  6. Map<String, dynamic>? onPlatform,
  7. Object? tags,
  8. TestLocation? location,
  9. int? retry,
  10. bool solo = false,
})

Creates a group of tests.

Implementation

void group(
  String name,
  void Function() body, {
  String? testOn,
  Timeout? timeout,
  Object? skip,
  Map<String, dynamic>? onPlatform,
  Object? tags,
  TestLocation? location,
  int? retry,
  bool solo = false,
}) {
  _checkNotBuilt('group');

  final fullTestPrefix = _prefix(name);
  if (_fullTestName != null && !_fullTestName.startsWith(fullTestPrefix)) {
    return;
  }

  var newMetadata = Metadata.parse(
    testOn: testOn,
    timeout: timeout,
    skip: skip,
    onPlatform: onPlatform,
    tags: tags,
    retry: _noRetry ? 0 : retry,
  );
  newMetadata.validatePlatformSelectors(_platformVariables);
  var metadata = _metadata.merge(newMetadata);
  var trace = _collectTraces ? Trace.current(2) : null;

  var declarer = Declarer._(
    this,
    fullTestPrefix,
    metadata,
    _platformVariables,
    _collectTraces,
    trace,
    location,
    _noRetry,
    _fullTestName,
    _seenNames,
    _isStandalone,
  );
  declarer.declare(() {
    // Cast to dynamic to avoid the analyzer complaining about us using the
    // result of a void method.
    var result = (body as dynamic)();
    if (result is! Future) return;
    throw ArgumentError('Groups may not be async.');
  });
  _addEntry(declarer.build());

  if (solo || declarer._solo) {
    _soloEntries.add(_entries.last);
  }
}