Skip to content

Commit cd8cdec

Browse files
authored
Use test app for Sessions e2e test (#4881)
* Use test app for Sessions e2e test * Add test lab plugin * Use firebase-sessions branch * Increase time to log session to 60 seconds
1 parent 229d597 commit cd8cdec

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed

.github/workflows/sessions-e2e.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ env:
1212
SESSIONS_E2E_GOOGLE_SERVICES: ${{ secrets.SESSIONS_E2E_GOOGLE_SERVICES }}
1313

1414
jobs:
15-
build:
15+
test:
1616

1717
runs-on: ubuntu-latest
1818

@@ -42,4 +42,4 @@ jobs:
4242
FTL_RESULTS_BUCKET: fireescape
4343
FIREBASE_APP_CHECK_DEBUG_SECRET: ${{ secrets.FIREBASE_APP_CHECK_DEBUG_SECRET }}
4444
run: |
45-
./gradlew :firebase-sessions:deviceCheck withErrorProne -PtargetBackend="prod"
45+
./gradlew :firebase-sessions:test-app:deviceCheck withErrorProne -PtargetBackend="prod"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2023 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.firebase.testing.sessions
18+
19+
import androidx.test.core.app.ApplicationProvider
20+
import androidx.test.ext.junit.runners.AndroidJUnit4
21+
import com.google.common.truth.Truth.assertThat
22+
import com.google.firebase.FirebaseApp
23+
import com.google.firebase.ktx.Firebase
24+
import com.google.firebase.ktx.initialize
25+
import com.google.firebase.sessions.FirebaseSessions
26+
import org.junit.After
27+
import org.junit.Before
28+
import org.junit.Test
29+
import org.junit.runner.RunWith
30+
31+
@RunWith(AndroidJUnit4::class)
32+
class FirebaseSessionsTest {
33+
@Before
34+
fun setUp() {
35+
Firebase.initialize(ApplicationProvider.getApplicationContext())
36+
}
37+
38+
@After
39+
fun cleanUp() {
40+
FirebaseApp.clearInstancesForTest()
41+
}
42+
43+
@Test
44+
fun initializeSession() {
45+
// Force the Firebase Sessions SDK to initialize.
46+
assertThat(FirebaseSessions.instance.greeting()).isEqualTo("Matt says hi!")
47+
48+
// Wait for the session start event to send.
49+
// TODO(mrober): Setup logger we can access from tests.
50+
Thread.sleep(TIME_TO_LOG_SESSION)
51+
}
52+
53+
companion object {
54+
private const val TIME_TO_LOG_SESSION = 60_000L
55+
}
56+
}

firebase-sessions/test-app/test-app.gradle.kts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
@file:Suppress("DEPRECATION") // App projects should still use FirebaseTestLabPlugin.
2+
3+
import com.google.firebase.gradle.plugins.ci.device.FirebaseTestLabPlugin
4+
15
/*
26
* Copyright 2023 Google LLC
37
*
@@ -30,6 +34,7 @@ android {
3034
versionCode = 1
3135
versionName = "1.0"
3236
multiDexEnabled = true
37+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
3338
}
3439
compileOptions {
3540
sourceCompatibility = JavaVersion.VERSION_1_8
@@ -46,8 +51,15 @@ dependencies {
4651
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
4752
implementation("androidx.core:core-ktx:1.9.0")
4853
implementation("com.google.android.material:material:1.8.0")
54+
55+
androidTestImplementation("com.google.firebase:firebase-common-ktx:20.3.2")
56+
androidTestImplementation(libs.androidx.test.junit)
57+
androidTestImplementation(libs.androidx.test.runner)
58+
androidTestImplementation(libs.truth)
4959
}
5060

5161
extra["packageName"] = "com.google.firebase.testing.sessions"
5262

5363
apply(from = "../../gradle/googleServices.gradle")
64+
65+
apply<FirebaseTestLabPlugin>()

0 commit comments

Comments
 (0)