Make it possible to override the FLUTTER_TEST env variable (#34301)

* Make it possible to override the FLUTTER_TEST env variable without unsetting it.

* Switch to using platform instead of Platform.

* Document the bindings, and introduce tests that initialize multiple WidgetsBindings with different environments.

* Add tests for the flutter platform test.

* Add license headers

* Fix lints

* Remove trailing whitespace

* Respond to Jonahs comments

* Respond to Ians comments

* Mock out the HttpServer in flutter_platform_test

* Mock out the HttpServer in flutter_platform_test

* Explain why we mock out the HttpServer in flutter_platform_test
This commit is contained in:
David Shuckerow
2019-06-28 10:37:27 -07:00
committed by GitHub
parent 66273157f0
commit df6e4d4872
8 changed files with 204 additions and 14 deletions

View File

@@ -0,0 +1,16 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
test('$WidgetsBinding initializes with $LiveTestWidgetsFlutterBinding when FLUTTER_TEST = "false"', () {
TestWidgetsFlutterBinding.ensureInitialized(<String, String>{'FLUTTER_TEST': 'false'});
expect(WidgetsBinding.instance, isInstanceOf<LiveTestWidgetsFlutterBinding>());
}, onPlatform: const <String, dynamic>{
'browser': <Skip>[Skip('Browser will not use the live binding')]
});
}

View File

@@ -0,0 +1,14 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
test('$WidgetsBinding initializes with $AutomatedTestWidgetsFlutterBinding when FLUTTER_TEST has a value that is not "true" or "false"', () {
TestWidgetsFlutterBinding.ensureInitialized(<String, String>{'FLUTTER_TEST': 'value that is neither "true" nor "false"'});
expect(WidgetsBinding.instance, isInstanceOf<AutomatedTestWidgetsFlutterBinding>());
});
}

View File

@@ -0,0 +1,14 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
test('$WidgetsBinding initializes with $AutomatedTestWidgetsFlutterBinding when FLUTTER_TEST is defined but null', () {
TestWidgetsFlutterBinding.ensureInitialized(<String, String>{'FLUTTER_TEST': null});
expect(WidgetsBinding.instance, isInstanceOf<AutomatedTestWidgetsFlutterBinding>());
});
}

View File

@@ -0,0 +1,14 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
test('$WidgetsBinding initializes with $AutomatedTestWidgetsFlutterBinding when FLUTTER_TEST = "true"', () {
TestWidgetsFlutterBinding.ensureInitialized(<String, String>{'FLUTTER_TEST': 'true'});
expect(WidgetsBinding.instance, isInstanceOf<AutomatedTestWidgetsFlutterBinding>());
});
}

View File

@@ -0,0 +1,14 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
test('$WidgetsBinding initializes with $LiveTestWidgetsFlutterBinding when the environment does not contain FLUTTER_TEST', () {
TestWidgetsFlutterBinding.ensureInitialized(<String, String>{});
expect(WidgetsBinding.instance, isInstanceOf<LiveTestWidgetsFlutterBinding>());
});
}