Skip to content

Commit

Permalink
Adds new ResizeDisplayTest
Browse files Browse the repository at this point in the history
Adds new ResizeDisplayTest
  • Loading branch information
JoseAlcerreca authored Feb 5, 2024
2 parents 910bd7c + e859e49 commit 18a85b3
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 3 deletions.
8 changes: 6 additions & 2 deletions ui/espresso/EspressoDeviceSample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ android {
compileSdk 33
defaultConfig {
applicationId "com.example.android.testing.espresso.EspressoDeviceSample"
minSdkVersion 14
minSdkVersion 19
targetSdkVersion 33
versionCode 1
versionName "1.0"
Expand All @@ -16,12 +16,16 @@ android {
productFlavors {
}
testOptions {

emulatorControl {
enable = true
}
unitTests {
includeAndroidResources = true
}
managedDevices {
devices {
// run with ../gradlew nexusOneApi30DebugAndroidTest
// run with ./gradlew nexusOneApi30DebugAndroidTest
nexusOneApi30(com.android.build.api.dsl.ManagedVirtualDevice) {
// A lower resolution device is used here for better emulator performance
device = "Nexus One"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.android.testing.espresso.EspressoDeviceSample

import androidx.test.espresso.device.DeviceInteraction.Companion.setDisplaySize
import androidx.test.espresso.device.EspressoDevice.Companion.onDevice
import androidx.test.espresso.device.filter.RequiresDisplay
import androidx.test.espresso.device.rules.DisplaySizeRule
import androidx.test.espresso.device.sizeclass.HeightSizeClass
import androidx.test.espresso.device.sizeclass.WidthSizeClass
import androidx.test.espresso.device.sizeclass.WidthSizeClass.Companion.WidthSizeClassEnum
import androidx.test.espresso.device.sizeclass.HeightSizeClass.Companion.HeightSizeClassEnum
import androidx.test.ext.junit.rules.activityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import androidx.test.espresso.device.sizeclass.WidthSizeClass.Companion.WidthSizeClassEnum.EXPANDED as EXPANDED1

/*
* Illustrates usage of [onDevice] API to change the display size.
*/
@RunWith(AndroidJUnit4::class)
class ResizeDisplayTest {

@get:Rule(order = 1) var activityScenarioRule = activityScenarioRule<MainActivity>()

// Test rule for restoring device to its starting display size when a test case finishes
@get:Rule(order = 2) var displaySizeRule: DisplaySizeRule = DisplaySizeRule()

@Test
fun resizeWindow_compact() {
onDevice().setDisplaySize(
widthSizeClass = WidthSizeClass.COMPACT,
heightSizeClass = HeightSizeClass.COMPACT
)
// Verify visual attributes or state restoration
}

/**
* Setting the display size to EXPANDED would fail in small devices, so the [RequiresDisplay]
* annotation prevents this test from being run on devices outside the EXPANDED buckets.
*/
@RequiresDisplay(
widthSizeClass = WidthSizeClassEnum.EXPANDED,
heightSizeClass = HeightSizeClassEnum.EXPANDED
)
@Test
fun resizeWindow_expanded() {
onDevice().setDisplaySize(
widthSizeClass = WidthSizeClass.EXPANDED,
heightSizeClass = HeightSizeClass.EXPANDED
)
// Verify visual attributes or state restoration
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />

<application
android:icon="@drawable/ic_launcher"
Expand Down
2 changes: 1 addition & 1 deletion ui/espresso/EspressoDeviceSample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ ext {
robolectricVersion = "4.10.3"
extTruthVersion = "1.6.0-alpha01"
extJUnitVersion = "1.2.0-alpha01"
espressoDeviceVersion = "1.0.0-alpha01"
espressoDeviceVersion = "1.0.0-alpha07"
}
1 change: 1 addition & 0 deletions ui/espresso/EspressoDeviceSample/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false
android.nonTransitiveRClass=false
android.useAndroidX=true
android.experimental.androidTest.enableEmulatorControl=true

0 comments on commit 18a85b3

Please sign in to comment.