title: Bad state: Mock method was not called within `when()`. Was a real method called?
body: <p>I'm trying to make a mock of an <code>httpRequest</code> in flutter using mockito.</p>
  
  <p>Here I define a global http client:</p>
  
  <pre class="lang-dart prettyprint-override"><code>library utgard.globals;
  
  import 'package:http/http.dart' as http;
  
  http.Client httpClient = http.Client();
  </code></pre>
  
  <p>Then I replace in integration testing:</p>
  
  <pre class="lang-dart prettyprint-override"><code>import 'package:flutter_driver/driver_extension.dart';
  import 'package:http/http.dart' as http;
  import 'package:utgard/globals.dart' as globals;
  import 'package:mockito/mockito.dart';
  
  import 'package:utgard/main.dart' as app;
  
  class MockClient extends Mock implements http.Client {}
  
  void main() {
    final MockClient client = MockClient();
    globals.httpClient = client;
  
    enableFlutterDriverExtension();
  
    app.main();
  }
  </code></pre>
  
  <p>Then I try to use <code>when</code> of mockito:</p>
  
  <pre class="lang-dart prettyprint-override"><code>test('login with correct password', () async {
        final client = MockClient();
  
        when(globals.httpClient.post('http://www.google.com'))
            .thenAnswer((_) async =&gt; http.Response('{"title": "Test"}', 200));
  
        await driver.enterText('000000');
        await driver.tap(loginContinuePasswordButton);
      });
  </code></pre>
  
  <p>But I receive the following error:</p>
  
  <blockquote>
    <p>Bad state: Mock method was not called within <code>when()</code>. Was a real method called?</p>
  </blockquote>