title: How to `setUp` a `WidgetTester` for Multiple Tests in Flutter
body: <h1>1. The Problem</h1>
  
  <p>The <code>testWidgets</code> function is apparently only a subcase of the <code>test</code> function.</p>
  
  <p>A use case I'm trying to solve right now is to pump the same widget for multiple <code>testWidgets</code>, a <code>setUp</code> for multiple <code>testWidgets</code>. However, how can I do this if it creates a new instance inside each test?</p>
  
  <p>I've tried to initialize a <code>WidgetTester</code> outside the tests, in the <code>main()</code>, but <code>WidgetTester</code> has only a private constructor: </p>
  
  <pre class="lang-dart prettyprint-override"><code>class WidgetTester 
    extends WidgetController 
      implements HitTestDispatcher, TickerProvider {
    WidgetTester._(TestWidgetsFlutterBinding binding) : super(binding) {
      if (binding is LiveTestWidgetsFlutterBinding)
        binding.deviceEventDispatcher = this;
  }
  </code></pre>
  
  <p>I don't quite get how the Flutter team made this work, but initializing a <code>WidgetTester</code> in the same way they did inside the <code>testWidgets</code> function isn't working for me:</p>
  
  <pre class="lang-dart prettyprint-override"><code>final TestWidgetsFlutterBinding binding 
    = TestWidgetsFlutterBinding.ensureInitialized() 
      as TestWidgetsFlutterBinding;
  final WidgetTester tester = WidgetTester._(binding);
  </code></pre>
  
  <h1>2. An Example</h1>
  
  <p>A simple example would be to try to break down the tests of the Flutter demo that is created with each new Flutter project from <code>flutter create</code>. In it, we could try to separate the initial setup test of the app from the tapping action test:</p>
  
  <pre class="lang-dart prettyprint-override"><code>testWidgets('Initial setup', (WidgetTester tester) async {
    await tester.pumpWidget(MyApp());
  
    expect(find.text('0'), findsOneWidget);
    expect(find.text('1'), findsNothing);
  });
  
  testWidgets('Increment the counter on tap', (WidgetTester tester) async {
    await tester.pumpWidget(MyApp());
  
    await tester.tap(find.byIcon(Icons.add));
    await tester.pump();
  
    expect(find.text('0'), findsNothing);
    expect(find.text('1'), findsOneWidget);
  });
  </code></pre>
  
  <p>The idea would be to try to move the <code>await tester.pumpWidget(MyApp());</code> into a <code>setUp</code> function.</p>