1
私はフラッタウェブサイト上introduction to platform-specific plugins/channelsを読んで、私はurl_launcher
のように、プラグインのいくつかの簡単な例をブラウズ:私はしませんので、Flutterプラットフォームのチャンネル/プラグインを模擬/スタブするにはどうしたらいいですか?
// Copyright 2017 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 'dart:async';
import 'package:flutter/services.dart';
const _channel = const MethodChannel('plugins.flutter.io/url_launcher');
/// Parses the specified URL string and delegates handling of it to the
/// underlying platform.
///
/// The returned future completes with a [PlatformException] on invalid URLs and
/// schemes which cannot be handled, that is when [canLaunch] would complete
/// with false.
Future<Null> launch(String urlString) {
return _channel.invokeMethod(
'launch',
urlString,
);
}
は、どのように私はモックやスタブチャネルすることができます実際のデバイス(AndroidまたはiOSを実行している)に頼らざるを得ず、実際にURLを起動していますか?
読者が理解してちょうどそう、MethodChannel'は、標準的な( 'const')オブジェクトである'ので、私はプラグインの作者が 'channel'をpublicにしていなくても自分のパッケージで' setMockMethodCallHandler'を作成できますか? – matanlurey
プラグインは、デフォルトのものを使用する代わりにMethodChannel引数をとる@visibleForTestingコンストラクタを提供する必要があります。 url_launcherはまだこれを行いませんが、firebase_analyticsプラグインはこのパターンの例です。最終的には、ほとんどのプラグインがこのパターンに従い、よりテスト可能になることを期待しています。 https://github.com/flutter/firebase_analytics/blob/master/lib/firebase_analytics.dart –