Skip to content

Commit 0b09c42

Browse files
author
babichev.a
committed
rotation android ui test
1 parent 47a23e2 commit 0b09c42

8 files changed

Lines changed: 83 additions & 7 deletions

File tree

android-compose-app/build.gradle.kts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ android {
6262
compose = true
6363
}
6464
packagingOptions.resources.excludes.add("/META-INF/{AL2.0,LGPL2.1}")
65-
testOptions.execution = "ANDROIDX_TEST_ORCHESTRATOR"
65+
testOptions{
66+
execution = "ANDROIDX_TEST_ORCHESTRATOR"
67+
emulatorControl.enable = true
68+
}
6669
}
6770

6871
dependencies {
@@ -80,6 +83,7 @@ dependencies {
8083
implementation(platform(libs.firebase.bom))
8184
implementation(libs.firebase.analytics)
8285
implementation(libs.firebase.crashlytics)
86+
implementation(libs.androidx.tracing)
8387
debugImplementation(libs.leakCanary.android)
8488
debugImplementation(libs.leakCanary.android.process)
8589
implementation(libs.leakCanary.plumber.android)
@@ -91,6 +95,7 @@ dependencies {
9195
androidTestImplementation(libs.androidx.test.runner)
9296
androidTestUtil(libs.androidx.test.orchestrator)
9397
androidTestImplementation(libs.espresso.core)
98+
androidTestImplementation(libs.espresso.device)
9499
androidTestImplementation(compose.desktop.uiTestJUnit4)
95100
androidTestImplementation(libs.turbine)
96101
androidTestImplementation(libs.leakCanary.android.instrumentation)
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.softartdev.notedelight.ui
2+
3+
import android.content.Context
4+
import androidx.compose.ui.test.*
5+
import androidx.compose.ui.test.junit4.createAndroidComposeRule
6+
import androidx.test.core.app.ApplicationProvider
7+
import androidx.test.espresso.IdlingRegistry
8+
import androidx.test.espresso.device.DeviceInteraction.Companion.setScreenOrientation
9+
import androidx.test.espresso.device.EspressoDevice.Companion.onDevice
10+
import androidx.test.espresso.device.action.ScreenOrientation
11+
import androidx.test.espresso.device.rules.ScreenOrientationRule
12+
import androidx.test.ext.junit.runners.AndroidJUnit4
13+
import androidx.test.filters.LargeTest
14+
import com.softartdev.notedelight.ComposeIdlingRes
15+
import com.softartdev.notedelight.MainActivity
16+
import com.softartdev.notedelight.shared.R
17+
import com.softartdev.notedelight.shared.base.IdlingRes
18+
import leakcanary.DetectLeaksAfterTestSuccess
19+
import leakcanary.TestDescriptionHolder
20+
import org.junit.After
21+
import org.junit.Before
22+
import org.junit.Rule
23+
import org.junit.Test
24+
import org.junit.rules.RuleChain
25+
import org.junit.runner.RunWith
26+
27+
@LargeTest
28+
@RunWith(AndroidJUnit4::class)
29+
class RotationTest {
30+
31+
private val composeTestRule = createAndroidComposeRule<MainActivity>()
32+
33+
@get:Rule
34+
val rules: RuleChain = RuleChain.outerRule(TestDescriptionHolder)
35+
.around(DetectLeaksAfterTestSuccess())
36+
.around(ScreenOrientationRule(ScreenOrientation.PORTRAIT))
37+
.around(composeTestRule)
38+
39+
private val context = ApplicationProvider.getApplicationContext<Context>()
40+
41+
@Before
42+
fun registerIdlingResource() {
43+
IdlingRegistry.getInstance().register(IdlingRes.countingIdlingResource)
44+
composeTestRule.registerIdlingResource(ComposeIdlingRes)
45+
}
46+
47+
@After
48+
fun unregisterIdlingResource() {
49+
composeTestRule.unregisterIdlingResource(ComposeIdlingRes)
50+
IdlingRegistry.getInstance().unregister(IdlingRes.countingIdlingResource)
51+
}
52+
53+
@Test
54+
fun rotationTest() {
55+
composeTestRule
56+
.onNodeWithContentDescription(label = context.getString(R.string.create_note))
57+
.assertIsDisplayed()
58+
59+
onDevice().setScreenOrientation(ScreenOrientation.LANDSCAPE)
60+
61+
composeTestRule
62+
.onNodeWithContentDescription(label = context.getString(R.string.create_note))
63+
.assertIsDisplayed()
64+
65+
onDevice().setScreenOrientation(ScreenOrientation.PORTRAIT)
66+
}
67+
}

gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ org.gradle.parallel=true
33
org.gradle.daemon=true
44
org.gradle.configureondemand=true
55
org.gradle.caching=true
6+
org.gradle.configuration-cache=true
67

78
kotlin.code.style=official
89
#kotlin.native.binary.memoryModel=experimental
@@ -17,5 +18,6 @@ org.jetbrains.compose.experimental.uikit.enabled=true
1718
android.useAndroidX=true
1819
android.nonTransitiveRClass=true
1920
android.nonFinalResIds=true
21+
android.experimental.androidTest.enableEmulatorControl=true
2022

2123
xcodeproj=iosApp/iosApp.xcworkspace

gradle/libs.versions.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ androidxCoreSplashscreen = "1.0.1"
2828
androidxLegacySupport = "1.0.0"
2929
androidxPreference = "1.2.1"
3030
androidxMultidex = "2.0.1"
31+
androidxTracing = "1.2.0"
3132
androidxLifecycle = "2.7.0"
3233
androidxArch = "2.2.0"
3334
androidxTestExt = "1.1.5"
@@ -95,6 +96,7 @@ androidx-core-splashscreen = { module = "androidx.core:core-splashscreen", versi
9596
androidx-legacy-support = { module = "androidx.legacy:legacy-support-v4", version.ref = "androidxLegacySupport" }
9697
androidx-preference = { module = "androidx.preference:preference", version.ref = "androidxPreference" }
9798
androidx-multidex = { module = "androidx.multidex:multidex", version.ref = "androidxMultidex" }
99+
androidx-tracing = { module = "androidx.tracing:tracing", version.ref = "androidxTracing" }
98100

99101
androidx-lifecycle-runtime = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "androidxLifecycle" }
100102
androidx-lifecycle-viewmodel = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "androidxLifecycle" }
@@ -104,7 +106,6 @@ androidx-arch-core-runtime = { module = "androidx.arch.core:core-runtime", versi
104106
androidx-arch-core-testing = { module = "androidx.arch.core:core-testing", version.ref = "androidxArch" }
105107

106108
androidx-test-ext-junit = { module = "androidx.test.ext:junit", version.ref = "androidxTestExt" }
107-
108109
androidx-test-rules = { module = "androidx.test:rules", version.ref = "androidxTest" }
109110
androidx-test-runner = { module = "androidx.test:runner", version.ref = "androidxTest" }
110111
androidx-test-orchestrator = { module = "androidx.test:orchestrator", version.ref = "androidxTestOrchestrator" }
@@ -131,6 +132,7 @@ appdirs = { module = "net.harawata:appdirs", version.ref = "appdirs" }
131132

132133
espresso-core = { module = "androidx.test.espresso:espresso-core", version.ref = "espresso" }
133134
espresso-contrib = { module = "androidx.test.espresso:espresso-contrib", version.ref = "espresso" }
135+
espresso-device = { module = "androidx.test.espresso:espresso-device", version = "1.0.0-alpha08" }
134136
espresso-idling-resource = { module = "androidx.test.espresso:espresso-idling-resource", version.ref = "espresso" }
135137

136138
desugar = { module = "com.android.tools:desugar_jdk_libs", version.ref = "desugar" }

iosApp/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ SPEC CHECKSUMS:
2424

2525
PODFILE CHECKSUM: 0dc93a6f6109335ea8cd3f91d2c87cc8c99f04a3
2626

27-
COCOAPODS: 1.12.1
27+
COCOAPODS: 1.15.2

iosApp/Pods/Manifest.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

iosApp/Pods/Pods.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

iosApp/Pods/Target Support Files/Pods-iosApp/Pods-iosApp-frameworks.sh

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)