tearDownUI function

void tearDownUI(
  1. WidgetTesterCallback cb
)

Registers a function to be run after tests.

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

Implementation

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