Skip to content

A fully functional Android app built entirely with Kotlin and Jetpack Compose

Grant `POST_NOTIFICATIONS` permission in instrumented tests

Simon Marquis331e8cffaca5
diff --git a/feature/foryou/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreenTest.kt b/feature/foryou/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreenTest.kt
index eb27473bb..404ad55b9 100644
--- a/feature/foryou/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreenTest.kt
+++ b/feature/foryou/src/androidTest/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreenTest.kt
@@ -16,6 +16,7 @@
package com.google.samples.apps.nowinandroid.feature.foryou
+import android.Manifest
import androidx.activity.ComponentActivity
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.ui.test.assertHasClickAction
@@ -28,6 +29,8 @@ import androidx.compose.ui.test.onFirst
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performScrollToNode
+import androidx.test.rule.GrantPermissionRule
+import androidx.test.rule.GrantPermissionRule.grant
import com.google.samples.apps.nowinandroid.core.testing.data.followableTopicTestData
import com.google.samples.apps.nowinandroid.core.testing.data.userNewsResourcesTestData
import com.google.samples.apps.nowinandroid.core.ui.NewsFeedUiState
@@ -35,6 +38,10 @@ import org.junit.Rule
import org.junit.Test
class ForYouScreenTest {
+
+ @get:Rule
+ val permissionTestRule: GrantPermissionRule = grant(Manifest.permission.POST_NOTIFICATIONS)
+
@get:Rule
val composeTestRule = createAndroidComposeRule<ComponentActivity>()