This repository was archived by the owner on Aug 30, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 32
run sample app and do a simple E2E test #451
Draft
marandaneto
wants to merge
22
commits into
getsentry:master
Choose a base branch
from
marandaneto:ci/run-sample-app
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
58281d2
run sample app and do not crash
marandaneto a000f1c
wip
marandaneto 197368a
wip
marandaneto cd585d7
added make runsample
marandaneto 057ef7c
adding sleep hack
marandaneto 3717824
just a test
marandaneto 26dd8b7
run some ui tests
marandaneto a8570e8
add run connected
marandaneto 92b4046
fix
marandaneto b6c4edc
test
marandaneto a7a5f92
wip
marandaneto 3979285
test
marandaneto a619571
cleaning
marandaneto c598bfb
test
marandaneto 7d1eadb
just a test to simulate a crash
marandaneto 33b6831
simulate another error
marandaneto e95c973
rollback
marandaneto 7a10f45
wait 5s
marandaneto b544549
draft api check
marandaneto 9fcd445
fix missing dep
marandaneto c0220fb
draft
marandaneto 8126fe3
use reactivecircus/android-emulator-runner
marandaneto 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| name: Workflow Sample Install macOS | ||
| on: | ||
| push: | ||
| branches: | ||
| - master | ||
| pull_request: | ||
| branches: | ||
| - '*' | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: macos-latest | ||
|
|
||
| steps: | ||
| - name: Git checkout | ||
| uses: actions/checkout@v2 | ||
|
|
||
| # Zulu Community distribution of OpenJDK | ||
| - name: set up JDK 1.8 | ||
| uses: actions/setup-java@v1 | ||
| with: | ||
| java-version: 1.8 | ||
|
|
||
| - name: Generate Gradle checksums | ||
| run: | | ||
| find buildSrc -name "*.kt" -type f | sort | xargs shasum > gradle-checksums.txt | ||
| cat gradle-checksums.txt | ||
| - uses: actions/cache@v2 | ||
| with: | ||
| path: ~/.gradle | ||
| key: gradle-${{ hashFiles('gradle-checksums.txt') }}-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }} | ||
| restore-keys: | | ||
| gradle-${{ hashFiles('gradle-checksums.txt') }}- | ||
|
|
||
| - name: run tests | ||
| - uses: reactivecircus/android-emulator-runner@v2 | ||
| with: | ||
| api-level: 29 | ||
| ndk: 21.0.6113669 | ||
| cmake: 3.10.2.4988404 | ||
| script: make runConnectedTests | ||
|
|
||
| # We stop gradle at the end to make sure the cache folders | ||
| # don't contain any lock files and are free to be cached. | ||
| - name: Make stop | ||
| run: make stop |
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
100 changes: 100 additions & 0 deletions
100
sentry-sample/src/androidTest/java/io/sentry/sample/MainActivityTest.kt
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,100 @@ | ||
| package io.sentry.sample | ||
|
|
||
| import android.util.Log | ||
| import androidx.test.espresso.Espresso.onView | ||
| import androidx.test.espresso.action.ViewActions.click | ||
| import androidx.test.espresso.matcher.ViewMatchers.withId | ||
| import androidx.test.ext.junit.rules.activityScenarioRule | ||
| import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
| import androidx.test.filters.LargeTest | ||
| import io.sentry.core.protocol.SentryId | ||
| import java.util.Timer | ||
| import java.util.concurrent.CountDownLatch | ||
| import kotlin.concurrent.schedule | ||
| import okhttp3.ResponseBody | ||
| import org.junit.Rule | ||
| import org.junit.runner.RunWith | ||
| import retrofit2.Call | ||
| import retrofit2.Callback | ||
| import retrofit2.Response | ||
| import kotlin.test.Test | ||
| import kotlin.test.assertEquals | ||
| import kotlin.test.assertNotEquals | ||
| import kotlin.test.assertTrue | ||
| //import kotlin.test.BeforeTest | ||
|
|
||
| @LargeTest | ||
| @RunWith(AndroidJUnit4::class) | ||
| class MainActivityTest { | ||
|
|
||
| @get:Rule | ||
| val rule = activityScenarioRule<MainActivity>() | ||
|
|
||
| // @BeforeTest | ||
| // fun beforeTest() { | ||
| // val token = System.getenv("TEST") | ||
| // } | ||
|
|
||
| @Test | ||
| fun mainActivityTest() { | ||
| onView(withId(R.id.send_message)).perform(click()) | ||
| onView(withId(R.id.capture_exception)).perform(click()) | ||
| onView(withId(R.id.breadcrumb)).perform(click()) | ||
| onView(withId(R.id.native_capture)).perform(click()) | ||
|
|
||
| // val retrofit = Retrofit.Builder() | ||
| // .baseUrl("https://sentry.io/") | ||
| // .client(OkHttpClient.Builder().addInterceptor { chain -> | ||
| // // token from https://sentry.io/settings/account/api/auth-tokens/ | ||
| // val request = chain.request().newBuilder().addHeader("Authorization", "Bearer ${TOKEN}}").build() | ||
| // chain.proceed(request) | ||
| // }.build()) | ||
| // .build() | ||
| // val service = retrofit.create(SentryService::class.java) | ||
|
|
||
| // val count = CountDownLatch(4) | ||
| rule.scenario.onActivity { | ||
| val ids = it.ids | ||
| assertEquals(4, ids.size) | ||
| // val apiCallback = ApiCallback(count) | ||
| ids.forEach { id -> | ||
| assertNotEquals(SentryId.EMPTY_ID, id) | ||
|
|
||
| // TODO: try 5 times with interval of 1 sec? event might not be processed yet | ||
| // service.getEvent(id).enqueue(apiCallback) | ||
| } | ||
| } | ||
|
|
||
| val count = CountDownLatch(1) | ||
|
|
||
| Timer(true).schedule(5000) { | ||
| count.countDown() | ||
| } | ||
|
|
||
| // might be possible to replace with https://developer.android.com/training/testing/espresso/idling-resource | ||
| // little waiting time for getting events processed | ||
| // count.await(1, TimeUnit.MINUTES) | ||
| count.await() | ||
| } | ||
|
|
||
| internal class ApiCallback(private val count: CountDownLatch) : Callback<ResponseBody> { | ||
|
|
||
| override fun onFailure(call: Call<ResponseBody>, t: Throwable) { | ||
| Log.e("Sentry", "error: ${t.message}", t) | ||
| throw t | ||
| } | ||
|
|
||
| override fun onResponse(call: Call<ResponseBody>, response: Response<ResponseBody>) { | ||
| // TODO: assert its content? right now ony checking if the event exist | ||
| if (!response.isSuccessful) { | ||
| Log.i("Sentry", response.message()) | ||
| Log.e("Sentry", "error: ${response.errorBody()?.string()}") | ||
| Log.i("Sentry", "http code: ${response.code()}") | ||
| } else { | ||
| Log.i("Sentry", "success: ${response.body()?.string()}") | ||
| } | ||
| assertTrue(response.isSuccessful) | ||
| count.countDown() | ||
| } | ||
| } | ||
| } | ||
11 changes: 11 additions & 0 deletions
11
sentry-sample/src/androidTest/java/io/sentry/sample/SentryService.kt
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,11 @@ | ||
| package io.sentry.sample | ||
|
|
||
| import okhttp3.ResponseBody | ||
| import retrofit2.Call | ||
| import retrofit2.http.GET | ||
| import retrofit2.http.Path | ||
|
|
||
| interface SentryService { | ||
| @GET("api/0/projects/sentry-test/android/events/{id}/") | ||
| fun getEvent(@Path("id") id: String): Call<ResponseBody> | ||
| } |
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
Oops, something went wrong.
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.
@bruno-garcia do you know if its possible to generate a token on demand? cus we can't read from a system env as this runs on the emulator.
also, it's not "nice" to leak the token on the code, Reverse engineering is too easy at this point.
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.
How would we get the generated token?
I agree it's not ideal to embed the key in the apk. We should be able to provide an apk alone and test it out since the testing code is not part of the apk