Skip to content

Commit

Permalink
Try removing robolectric from integration_test tests (#148803)
Browse files Browse the repository at this point in the history
May fix flutter/flutter#148393.

There are reports on the robolectric issue tracker of >`4.10.3` causing the error we are seeing
robolectric/robolectric#8158
The test doesn't actually need robolectric (and didn't originally use it, or flake before using it), but it was added in flutter/flutter#144348. We can safely remove it by mocking the call to `View.generateViewId()`, so try removing it and see if flakes go away.
  • Loading branch information
gmackall authored May 22, 2024
1 parent 4c929f0 commit eba7b97
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 596 deletions.
2 changes: 0 additions & 2 deletions packages/integration_test/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ android {
dependencies {
// TODO(egarciad): These dependencies should not be added to release builds.
// https://github.com/flutter/flutter/issues/56591
testImplementation 'androidx.test.ext:junit:1.1.4-alpha07'
testImplementation 'org.robolectric:robolectric:4.11'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-inline:5.1.0'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import org.junit.runner.RunWith;
import org.mockito.MockedStatic;
import org.mockito.Mockito;

import android.app.Activity;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import android.view.View;

import androidx.test.runner.AndroidJUnitRunner;

import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.android.FlutterFragment;
import io.flutter.embedding.android.FlutterFragmentActivity;
import io.flutter.embedding.android.FlutterView;

@RunWith(AndroidJUnit4.class)
public class FlutterDeviceScreenshotTest {
public class FlutterDeviceScreenshotTest extends AndroidJUnitRunner {
@Test
public void getFlutterView_returnsNullForNonFlutterActivity() {
Activity mockActivity = mock(Activity.class);
Expand All @@ -30,25 +32,36 @@ public void getFlutterView_returnsNullForNonFlutterActivity() {

@Test
public void getFlutterView_returnsFlutterViewForFlutterActivity() {
FlutterView mockFlutterView = mock(FlutterView.class);
FlutterActivity mockFlutterActivity = mock(FlutterActivity.class);
when(mockFlutterActivity.findViewById(FlutterActivity.FLUTTER_VIEW_ID))
.thenReturn(mockFlutterView);
assertEquals(
FlutterDeviceScreenshot.getFlutterView(mockFlutterActivity),
mockFlutterView
);
// Mock the static call to View.generateViewId that FlutterActivity.FLUTTER_VIEW_ID needs.
// For why this test currently doesn't use Robolectric,
// see https://github.com/flutter/flutter/pull/148803.
try (MockedStatic<View> mockedStatic = Mockito.mockStatic(View.class)) {
mockedStatic.when(View::generateViewId).thenReturn(123);
FlutterView mockFlutterView = mock(FlutterView.class);
FlutterActivity mockFlutterActivity = mock(FlutterActivity.class);
when(mockFlutterActivity.findViewById(FlutterActivity.FLUTTER_VIEW_ID))
.thenReturn(mockFlutterView);
assertEquals(
FlutterDeviceScreenshot.getFlutterView(mockFlutterActivity),
mockFlutterView
);
}
}

@Test
public void getFlutterView_returnsFlutterViewForFlutterFragmentActivity() {
FlutterView mockFlutterView = mock(FlutterView.class);
FlutterFragmentActivity mockFlutterFragmentActivity = mock(FlutterFragmentActivity.class);
when(mockFlutterFragmentActivity.findViewById(FlutterFragment.FLUTTER_VIEW_ID))
.thenReturn(mockFlutterView);
assertEquals(
FlutterDeviceScreenshot.getFlutterView(mockFlutterFragmentActivity),
mockFlutterView
);
// Mock the static call to View.generateViewId that FlutterFragment.FLUTTER_VIEW_ID needs.
// For why this test currently doesn't use Robolectric,
// see https://github.com/flutter/flutter/pull/148803.
try (MockedStatic<View> mockedStatic = Mockito.mockStatic(View.class)) {
FlutterView mockFlutterView = mock(FlutterView.class);
FlutterFragmentActivity mockFlutterFragmentActivity = mock(FlutterFragmentActivity.class);
when(mockFlutterFragmentActivity.findViewById(FlutterFragment.FLUTTER_VIEW_ID))
.thenReturn(mockFlutterView);
assertEquals(
FlutterDeviceScreenshot.getFlutterView(mockFlutterFragmentActivity),
mockFlutterView
);
}
}
}
156 changes: 0 additions & 156 deletions packages/integration_test/example/android/buildscript-gradle.lockfile

This file was deleted.

Loading

0 comments on commit eba7b97

Please sign in to comment.