add Android instrumentation test (#11063)
* add Android instrumentation test * add devicelab test * add to manifest.yaml * rename _smoke_test.dart to _smoketest.dart to prevent flutter test from picking it up * volatile fields; style fixes * use ConditionVariable; fix sh script
This commit is contained in:
@@ -56,4 +56,6 @@ dependencies {
|
||||
androidTestCompile 'com.android.support:support-annotations:25.4.0'
|
||||
androidTestCompile 'com.android.support.test:runner:0.5'
|
||||
androidTestCompile 'com.android.support.test:rules:0.5'
|
||||
androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
|
||||
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
// 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.
|
||||
|
||||
package io.flutter.examples.gallery;
|
||||
|
||||
import android.support.test.filters.LargeTest;
|
||||
import android.support.test.rule.ActivityTestRule;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@LargeTest
|
||||
public class FlutterGalleryInstrumentationTest {
|
||||
@Rule
|
||||
public ActivityTestRule<MainActivity> mActivityRule =
|
||||
new ActivityTestRule<>(MainActivity.class);
|
||||
|
||||
private MainActivity activity;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
activity = mActivityRule.getActivity();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void activityLoaded() throws Exception {
|
||||
FlutterGalleryInstrumentation instrumentation = activity.getInstrumentation();
|
||||
instrumentation.waitForTestToFinish();
|
||||
assertThat(instrumentation.isTestSuccessful(), is(true));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
// 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.
|
||||
|
||||
package io.flutter.examples.gallery;
|
||||
|
||||
import android.os.ConditionVariable;
|
||||
import io.flutter.plugin.common.MethodCall;
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
|
||||
import io.flutter.plugin.common.MethodChannel.Result;
|
||||
import io.flutter.view.FlutterView;
|
||||
|
||||
/** Instrumentation for testing using Android Espresso framework. */
|
||||
public class FlutterGalleryInstrumentation implements MethodCallHandler {
|
||||
|
||||
private final ConditionVariable testFinished = new ConditionVariable();
|
||||
private volatile boolean testSuccessful;
|
||||
|
||||
FlutterGalleryInstrumentation(FlutterView view) {
|
||||
new MethodChannel(view, "io.flutter.examples.gallery/TestLifecycleListener")
|
||||
.setMethodCallHandler(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMethodCall(MethodCall call, Result result) {
|
||||
testSuccessful = call.method.equals("success");
|
||||
testFinished.open();
|
||||
result.success(null);
|
||||
}
|
||||
|
||||
public boolean isTestSuccessful() {
|
||||
return testSuccessful;
|
||||
}
|
||||
|
||||
public void waitForTestToFinish() throws Exception {
|
||||
testFinished.block();
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,7 @@
|
||||
// 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.
|
||||
|
||||
package io.flutter.examples.gallery;
|
||||
|
||||
import android.os.Bundle;
|
||||
@@ -7,9 +11,17 @@ import io.flutter.plugins.GeneratedPluginRegistrant;
|
||||
|
||||
public class MainActivity extends FlutterActivity {
|
||||
|
||||
private FlutterGalleryInstrumentation instrumentation;
|
||||
|
||||
/** Instrumentation for testing. */
|
||||
public FlutterGalleryInstrumentation getInstrumentation() {
|
||||
return instrumentation;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
GeneratedPluginRegistrant.registerWith(this);
|
||||
instrumentation = new FlutterGalleryInstrumentation(this.getFlutterView());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user