setUpUI function

void setUpUI(
  1. WidgetTesterCallback cb
)

Registers a function to be run before tests.

Functions registered by setUpUI will be run after all other functions registered by setUp in parent or child groups. The functions will only be run when testUI is used to create the test case.

Implementation

void setUpUI(WidgetTesterCallback cb) {
  final setUpFunction = _UniqueWrapper(cb, StackTrace.current);
  setUp(() {
    setUpFunction.ran = false;
    _setUpUIs.add(setUpFunction);
  });
  tearDown(() {
    assert(_setUpUIs.contains(setUpFunction));
    assert(
      setUpFunction.ran,
      "A setUpUI function wasn't run. Likely, this means that testWidgets was used to create the test instead of testUI.\n"
      "${setUpFunction.stackTrace}",
    );
    _setUpUIs.remove(setUpFunction);
  });
  tearDownAll(() {
    assert(_setUpUIs.isEmpty);
  });
}