Skip to content

Use test app for Sessions e2e test #4881

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/sessions-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ env:
SESSIONS_E2E_GOOGLE_SERVICES: ${{ secrets.SESSIONS_E2E_GOOGLE_SERVICES }}

jobs:
build:
test:

runs-on: ubuntu-latest

Expand Down Expand Up @@ -42,4 +42,4 @@ jobs:
FTL_RESULTS_BUCKET: fireescape
FIREBASE_APP_CHECK_DEBUG_SECRET: ${{ secrets.FIREBASE_APP_CHECK_DEBUG_SECRET }}
run: |
./gradlew :firebase-sessions:deviceCheck withErrorProne -PtargetBackend="prod"
./gradlew :firebase-sessions:test-app:deviceCheck withErrorProne -PtargetBackend="prod"
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2023 Google LLC
*
* 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.google.firebase.testing.sessions

import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
import com.google.firebase.FirebaseApp
import com.google.firebase.ktx.Firebase
import com.google.firebase.ktx.initialize
import com.google.firebase.sessions.FirebaseSessions
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class FirebaseSessionsTest {
@Before
fun setUp() {
Firebase.initialize(ApplicationProvider.getApplicationContext())
}

@After
fun cleanUp() {
FirebaseApp.clearInstancesForTest()
}

@Test
fun initializeSession() {
// Force the Firebase Sessions SDK to initialize.
assertThat(FirebaseSessions.instance.greeting()).isEqualTo("Matt says hi!")

// Wait for the session start event to send.
// TODO(mrober): Setup logger we can access from tests.
Thread.sleep(TIME_TO_LOG_SESSION)
}

companion object {
private const val TIME_TO_LOG_SESSION = 60_000L
}
}
12 changes: 12 additions & 0 deletions firebase-sessions/test-app/test-app.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@file:Suppress("DEPRECATION") // App projects should still use FirebaseTestLabPlugin.

import com.google.firebase.gradle.plugins.ci.device.FirebaseTestLabPlugin

/*
* Copyright 2023 Google LLC
*
Expand Down Expand Up @@ -30,6 +34,7 @@ android {
versionCode = 1
versionName = "1.0"
multiDexEnabled = true
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
Expand All @@ -46,8 +51,15 @@ dependencies {
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("androidx.core:core-ktx:1.9.0")
implementation("com.google.android.material:material:1.8.0")

androidTestImplementation("com.google.firebase:firebase-common-ktx:20.3.2")
androidTestImplementation(libs.androidx.test.junit)
androidTestImplementation(libs.androidx.test.runner)
androidTestImplementation(libs.truth)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this dependency? truth

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer using Guava's Truth than JUnit's regular asserts. Truth reads much better, and other Firebase SDKs use it in their tests too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My comment was in the context of why we use that for the test app. For SDK's it makes sense to me. Do we have tests for the test app and we are using Guava's truth library for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh is there any reason we should avoid it?

Right now we do 1 Truth.assertThat(...) on the placeholder api. That is how the test verifies that Sessions and everything got initialized correctly in the test app for now. We could make a simpler assert like that the instance is not null? But after my TODO is resolved, I expect to add different asserts on the logs. E.g. assert that the session was successfully sent to firelog.

}

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

apply(from = "../../gradle/googleServices.gradle")

apply<FirebaseTestLabPlugin>()