Skip to content

Instantly share code, notes, and snippets.

@anangkur
Created February 23, 2022 05:14
Show Gist options
  • Save anangkur/40ae34959a590d82736106b3d016005b to your computer and use it in GitHub Desktop.
Save anangkur/40ae34959a590d82736106b3d016005b to your computer and use it in GitHub Desktop.
package com.anangkur.karumishotplayground
import android.util.Log
import com.karumi.shot.ScreenshotTest
import org.junit.Rule
import org.junit.Test
import androidx.test.ext.junit.rules.activityScenarioRule
class MainActivityScreenTest : ScreenshotTest {
@get:Rule
var activityScenarioRule = activityScenarioRule<MainActivity>()
@Test
fun activityTest() {
val activity = launchActivity()
compareScreenshot(activity)
}
// Hack needed until we fully support Activity Scenarios
private fun launchActivity(): MainActivity {
var activity: MainActivity? = null
activityScenarioRule.scenario.onActivity {
activity = it
}
while (activity == null) {
Log.d("MainActivityTest", "Waiting for activity to be initialized")
}
return activity!!
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment