-
Notifications
You must be signed in to change notification settings - Fork 626
Crashlytics smoke test stubs #2737
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5ab83f5
Crashlytics smoke tests
mrichards 6675140
Merge remote-tracking branch 'origin/master' into crashlytics-smoke-t…
mrichards cf7130c
Removed reflection from Crashlytics smoke tests.
mrichards db24d0b
Merge branch 'master' into crashlytics-smoke-tests
mrichards 67b4c63
Updated @VisibleForTesting annotations
mrichards 2f1569a
Applied gJF
mrichards File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
smoke-tests/src/main/java/com/google/firebase/crashlytics/CrashlyticsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright 2021 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.crashlytics; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import android.os.Bundle; | ||
import androidx.test.core.app.ApplicationProvider; | ||
import com.google.firebase.analytics.FirebaseAnalytics; | ||
|
||
import androidx.test.runner.AndroidJUnit4; | ||
import com.google.firebase.crashlytics.internal.breadcrumbs.BreadcrumbSource; | ||
import com.google.firebase.crashlytics.internal.common.CrashlyticsCore; | ||
import java.lang.reflect.Field; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
/** | ||
* This class is in the com.google.firebase.crashlytics package to access FirebaseCrashlytics's | ||
* package-private fields. | ||
**/ | ||
@RunWith(AndroidJUnit4.class) | ||
public final class CrashlyticsTest { | ||
|
||
@Test | ||
public void analyticsIntegration() { | ||
// Validates that Firebase Analytics and Crashlytics interoperability is working, by confirming | ||
// that events sent to Firebase Analytics are received by the Crashlytics breadcrumb handler. | ||
try { | ||
BreadcrumbSource breadcrumbSource = FirebaseCrashlytics.getInstance().core.breadcrumbSource; | ||
final CountDownLatch eventReceivedLatch = new CountDownLatch(1); | ||
breadcrumbSource.registerBreadcrumbHandler(breadcrumbHandler -> { | ||
eventReceivedLatch.countDown(); | ||
}); | ||
|
||
Bundle eventBundle = new Bundle(); | ||
eventBundle.putString(FirebaseAnalytics.Param.ITEM_NAME, "testName"); | ||
FirebaseAnalytics.getInstance(ApplicationProvider.getApplicationContext()).logEvent( | ||
FirebaseAnalytics.Event.APP_OPEN, eventBundle); | ||
|
||
// Wait up to 2 seconds, which is plenty of time for the event | ||
eventReceivedLatch.await(2000, TimeUnit.MILLISECONDS); | ||
assertThat(eventReceivedLatch.getCount()).isEqualTo(0); | ||
|
||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Test | ||
public void setCustomKeys() { | ||
// For now, simply validate that the API does not throw any exception. A more robust functional | ||
// test could be implemented via reflection or monitoring logcat. | ||
FirebaseCrashlytics.getInstance().setCustomKey("TestKey", "TestValue"); | ||
} | ||
|
||
@Test | ||
public void log() { | ||
// For now, simply validate that the API does not throw any exception. A more robust functional | ||
// test could be implemented via reflection or monitoring logcat. | ||
FirebaseCrashlytics.getInstance().log("This is a log message"); | ||
} | ||
|
||
@Test | ||
public void didCrashOnPreviousExecution() { | ||
assertThat(FirebaseCrashlytics.getInstance().didCrashOnPreviousExecution()).isFalse(); | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you still add
@VisibleForTesting
?