Skip to content

Commit

Permalink
Upgrades leak canary, testing, androidx lifecycle.
Browse files Browse the repository at this point in the history
Note that we hold off on upgrading androidx activity, appcompat, etc. Those push androidx core past 1.6.0, which breaks https://github.com/cashapp/paparazzi. We should hold off until they catch up, which should happen soon after AS Bumblebee freezes.
  • Loading branch information
rjrjr committed Jan 25, 2022
1 parent 90ec1e4 commit 03ab545
Show file tree
Hide file tree
Showing 31 changed files with 158 additions and 69 deletions.
1 change: 0 additions & 1 deletion .buildscript/android-ui-tests.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
android {
defaultConfig {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArgument "listener", "leakcanary.FailTestOnLeakRunListener"
}

testOptions {
Expand Down
20 changes: 10 additions & 10 deletions buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ object Dependencies {
const val ui = "androidx.compose.ui:ui:1.1.0-rc01"
}

const val constraint_layout = "androidx.constraintlayout:constraintlayout:2.1.0"
const val constraint_layout = "androidx.constraintlayout:constraintlayout:2.1.2"
const val fragment = "androidx.fragment:fragment:1.3.6"
const val fragmentKtx = "androidx.fragment:fragment-ktx:1.3.6"
const val gridlayout = "androidx.gridlayout:gridlayout:1.0.0"

object Lifecycle {
const val ktx = "androidx.lifecycle:lifecycle-runtime-ktx:2.3.1"
const val viewModel = "androidx.lifecycle:lifecycle-viewmodel:2.3.1"
const val viewModelKtx = "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1"
const val ktx = "androidx.lifecycle:lifecycle-runtime-ktx:2.4.0"
const val viewModel = "androidx.lifecycle:lifecycle-viewmodel:2.4.0"
const val viewModelKtx = "androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0"
const val viewModelSavedState = "androidx.lifecycle:lifecycle-viewmodel-savedstate:1.1.0"
}

Expand All @@ -53,7 +53,7 @@ object Dependencies {

// Required for Dungeon Crawler sample.
const val desugar_jdk_libs = "com.android.tools:desugar_jdk_libs:1.1.5"
const val leakcanary = "com.squareup.leakcanary:leakcanary-android:2.7"
const val leakcanary = "com.squareup.leakcanary:leakcanary-android:2.8.1"
const val radiography = "com.squareup.radiography:radiography:2.4.0"
const val rxandroid2 = "io.reactivex.rxjava2:rxandroid:2.1.1"
const val seismic = "com.squareup:seismic:1.0.2"
Expand Down Expand Up @@ -126,23 +126,23 @@ object Dependencies {
object AndroidX {
const val compose = "androidx.compose.ui:ui-test-junit4:1.0.1"
const val core = "androidx.test:core:1.3.0"
const val lifecycle = "androidx.lifecycle:lifecycle-runtime-testing:2.3.1"
const val lifecycle = "androidx.lifecycle:lifecycle-runtime-testing:2.4.0"

object Espresso {
const val core = "androidx.test.espresso:espresso-core:3.3.0"
const val idlingResource = "androidx.test.espresso:espresso-idling-resource:3.3.0"
const val intents = "androidx.test.espresso:espresso-intents:3.3.0"
}

const val junitExt = "androidx.test.ext:junit:1.1.2"
const val runner = "androidx.test:runner:1.3.0"
const val truthExt = "androidx.test.ext:truth:1.3.0"
const val junitExt = "androidx.test.ext:junit:1.1.3"
const val runner = "androidx.test:runner:1.4.0"
const val truthExt = "androidx.test.ext:truth:1.4.0"
const val uiautomator = "androidx.test.uiautomator:uiautomator:2.2.0"
}

const val hamcrestCore = "org.hamcrest:hamcrest-core:2.2"
const val junit = "junit:junit:4.13.2"
const val leakcanaryInstrumentation = "com.squareup.leakcanary:leakcanary-android-instrumentation:2.7"
const val leakcanaryInstrumentation = "com.squareup.leakcanary:leakcanary-android-instrumentation:2.8.1"
const val mockito = "org.mockito:mockito-core:3.3.3"
const val robolectric = "org.robolectric:robolectric:4.5.1"
const val truth = "com.google.truth:truth:1.1.3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ import androidx.compose.ui.test.performClick
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import com.squareup.workflow1.ui.internal.test.IdleAfterTestRule
import leakcanary.DetectLeaksAfterTestSuccess
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@OptIn(WorkflowUiExperimentalApi::class)
class HelloComposeTest {

@get:Rule val composeRule = createAndroidComposeRule<HelloComposeActivity>()
@get:Rule val idleAfterTest = IdleAfterTestRule
private val composeRule = createAndroidComposeRule<HelloComposeActivity>()
@get:Rule val rules: RuleChain = RuleChain.outerRule(DetectLeaksAfterTestSuccess())
.around(IdleAfterTestRule)
.around(composeRule)

@Test fun togglesBetweenStates() {
composeRule.onNodeWithText("Hello")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ import androidx.compose.ui.test.performClick
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import com.squareup.workflow1.ui.internal.test.IdleAfterTestRule
import leakcanary.DetectLeaksAfterTestSuccess
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@OptIn(WorkflowUiExperimentalApi::class)
class HelloBindingTest {

@get:Rule val composeRule = createAndroidComposeRule<HelloBindingActivity>()
@get:Rule val idleAfterTest = IdleAfterTestRule
private val composeRule = createAndroidComposeRule<HelloBindingActivity>()
@get:Rule val rules: RuleChain = RuleChain.outerRule(DetectLeaksAfterTestSuccess())
.around(IdleAfterTestRule)
.around(composeRule)

@Test fun togglesBetweenStates() {
composeRule.onNodeWithText("Hello")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ import androidx.compose.ui.test.performClick
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import com.squareup.workflow1.ui.internal.test.IdleAfterTestRule
import leakcanary.DetectLeaksAfterTestSuccess
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@OptIn(WorkflowUiExperimentalApi::class)
class HelloComposeWorkflowTest {

@get:Rule val composeRule = createAndroidComposeRule<HelloComposeWorkflowActivity>()
@get:Rule val idleAfterTest = IdleAfterTestRule
private val composeRule = createAndroidComposeRule<HelloComposeWorkflowActivity>()
@get:Rule val rules: RuleChain = RuleChain.outerRule(DetectLeaksAfterTestSuccess())
.around(IdleAfterTestRule)
.around(composeRule)

@Test fun togglesBetweenStates() {
composeRule.onNodeWithText("Hello")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@ import androidx.compose.ui.test.performClick
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import com.squareup.workflow1.ui.internal.test.IdleAfterTestRule
import leakcanary.DetectLeaksAfterTestSuccess
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@OptIn(WorkflowUiExperimentalApi::class)
class InlineRenderingTest {

@get:Rule val composeRule = createAndroidComposeRule<InlineRenderingActivity>()
@get:Rule val idleAfterTest = IdleAfterTestRule
private val composeRule = createAndroidComposeRule<InlineRenderingActivity>()
@get:Rule val rules: RuleChain = RuleChain.outerRule(DetectLeaksAfterTestSuccess())
.around(IdleAfterTestRule)
.around(composeRule)

@Test fun counterIncrements() {
composeRule.onNode(hasClickAction())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,20 @@ import androidx.test.platform.app.InstrumentationRegistry
import com.squareup.sample.compose.R
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import com.squareup.workflow1.ui.internal.test.IdleAfterTestRule
import leakcanary.DetectLeaksAfterTestSuccess
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@OptIn(WorkflowUiExperimentalApi::class)
class SampleLauncherTest {

@get:Rule val composeRule = createAndroidComposeRule<SampleLauncherActivity>()
@get:Rule val idleAfterTest = IdleAfterTestRule
private val composeRule = createAndroidComposeRule<SampleLauncherActivity>()
@get:Rule val rules: RuleChain = RuleChain.outerRule(DetectLeaksAfterTestSuccess())
.around(IdleAfterTestRule)
.around(composeRule)

@OptIn(ExperimentalTestApi::class)
@Test fun allSamplesLaunch() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import androidx.compose.ui.test.performClick
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import com.squareup.workflow1.ui.internal.test.IdleAfterTestRule
import leakcanary.DetectLeaksAfterTestSuccess
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.runner.RunWith

private const val ADD_BUTTON_TEXT = "Add Child"
Expand All @@ -21,8 +23,10 @@ private const val ADD_BUTTON_TEXT = "Add Child"
@OptIn(WorkflowUiExperimentalApi::class)
class NestedRenderingsTest {

@get:Rule val composeRule = createAndroidComposeRule<NestedRenderingsActivity>()
@get:Rule val idleAfterTest = IdleAfterTestRule
private val composeRule = createAndroidComposeRule<NestedRenderingsActivity>()
@get:Rule val rules: RuleChain = RuleChain.outerRule(DetectLeaksAfterTestSuccess())
.around(IdleAfterTestRule)
.around(composeRule)

@Test fun childrenAreAddedAndRemoved() {
composeRule.onNodeWithText(ADD_BUTTON_TEXT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ import androidx.compose.ui.test.onNodeWithText
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import com.squareup.workflow1.ui.internal.test.IdleAfterTestRule
import leakcanary.DetectLeaksAfterTestSuccess
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@OptIn(WorkflowUiExperimentalApi::class)
class PreviewTest {

@get:Rule val composeRule = createAndroidComposeRule<PreviewActivity>()
@get:Rule val idleAfterTest = IdleAfterTestRule
private val composeRule = createAndroidComposeRule<PreviewActivity>()
@get:Rule val rules: RuleChain = RuleChain.outerRule(DetectLeaksAfterTestSuccess())
.around(IdleAfterTestRule)
.around(composeRule)

@Test fun showsPreviewRendering() {
composeRule.onNodeWithText(ContactDetailsRendering::class.java.simpleName, substring = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@ import androidx.compose.ui.text.AnnotatedString
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import com.squareup.workflow1.ui.internal.test.IdleAfterTestRule
import leakcanary.DetectLeaksAfterTestSuccess
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@OptIn(WorkflowUiExperimentalApi::class)
class TextInputTest {

@get:Rule val composeRule = createAndroidComposeRule<TextInputActivity>()
@get:Rule val idleAfterTest = IdleAfterTestRule
private val composeRule = createAndroidComposeRule<TextInputActivity>()
@get:Rule val rules: RuleChain = RuleChain.outerRule(DetectLeaksAfterTestSuccess())
.around(IdleAfterTestRule)
.around(composeRule)

@OptIn(ExperimentalTestApi::class)
@Test fun allowsTextEditing() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import com.squareup.sample.container.poetryapp.R
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import com.squareup.workflow1.ui.internal.test.inAnyView
import leakcanary.DetectLeaksAfterTestSuccess
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@OptIn(WorkflowUiExperimentalApi::class)
class PoetryAppTest {

@get:Rule val scenarioRule = ActivityScenarioRule(PoetryActivity::class.java)
private val scenarioRule = ActivityScenarioRule(PoetryActivity::class.java)
@get:Rule val rules = RuleChain.outerRule(DetectLeaksAfterTestSuccess()).around(scenarioRule)!!

@Test fun launches() {
inAnyView(withText(R.string.poems))
.check(matches(isDisplayed()))
.check(matches(isDisplayed()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import com.squareup.workflow1.ui.internal.test.inAnyView
import leakcanary.DetectLeaksAfterTestSuccess
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@OptIn(WorkflowUiExperimentalApi::class)
class RavenAppTest {

@get:Rule val scenarioRule = ActivityScenarioRule(RavenActivity::class.java)
private val scenarioRule = ActivityScenarioRule(RavenActivity::class.java)
@get:Rule val rules = RuleChain.outerRule(DetectLeaksAfterTestSuccess()).around(scenarioRule)!!

@Test fun launches() {
inAnyView(withText("The Raven"))
.check(matches(isDisplayed()))
.check(matches(isDisplayed()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import com.squareup.workflow1.ui.internal.test.inAnyView
import com.squareup.workflow1.ui.internal.test.actuallyPressBack
import leakcanary.DetectLeaksAfterTestSuccess
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@OptIn(WorkflowUiExperimentalApi::class)
class HelloBackButtonEspressoTest {

@get:Rule val scenarioRule = ActivityScenarioRule(HelloBackButtonActivity::class.java)
private val scenarioRule = ActivityScenarioRule(HelloBackButtonActivity::class.java)
@get:Rule val rules = RuleChain.outerRule(DetectLeaksAfterTestSuccess()).around(scenarioRule)!!

@Test fun wrappedTakesPrecedence() {
inAnyView(withId(R.id.hello_message)).apply {
Expand Down
1 change: 0 additions & 1 deletion samples/dungeon/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ android {
multiDexEnabled = true

testInstrumentationRunner = "com.squareup.sample.dungeon.DungeonTestRunner"
testInstrumentationRunnerArguments["listener"] = "leakcanary.FailTestOnLeakRunListener"
}

compileOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import com.squareup.workflow1.ui.internal.test.inAnyView
import leakcanary.DetectLeaksAfterTestSuccess
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@OptIn(WorkflowUiExperimentalApi::class)
class DungeonAppTest {

@get:Rule val scenarioRule = ActivityScenarioRule(DungeonActivity::class.java)
private val scenarioRule = ActivityScenarioRule(DungeonActivity::class.java)
@get:Rule val rules = RuleChain.outerRule(DetectLeaksAfterTestSuccess()).around(scenarioRule)!!

@Test fun loadsBoardsList() {
inAnyView(withText(R.string.boards_list_label))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SdkSuppress
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import com.squareup.workflow1.ui.internal.test.inAnyView
import leakcanary.DetectLeaksAfterTestSuccess
import org.hamcrest.Matchers.containsString
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.runner.RunWith

// Life is too short to debug why LeakCanary breaks this on API 21
Expand All @@ -22,7 +24,8 @@ import org.junit.runner.RunWith
@OptIn(WorkflowUiExperimentalApi::class)
class HelloWorkflowFragmentAppTest {

@get:Rule val scenarioRule = ActivityScenarioRule(HelloWorkflowFragmentActivity::class.java)
private val scenarioRule = ActivityScenarioRule(HelloWorkflowFragmentActivity::class.java)
@get:Rule val rules = RuleChain.outerRule(DetectLeaksAfterTestSuccess()).around(scenarioRule)!!

@Test fun togglesHelloAndGoodbye() {
inAnyView(withText(containsString("Hello")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import com.squareup.workflow1.ui.internal.test.inAnyView
import leakcanary.DetectLeaksAfterTestSuccess
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@OptIn(WorkflowUiExperimentalApi::class)
class HelloWorkflowAppTest {

@get:Rule val scenarioRule = ActivityScenarioRule(HelloWorkflowActivity::class.java)
private val scenarioRule = ActivityScenarioRule(HelloWorkflowActivity::class.java)
@get:Rule val rules = RuleChain.outerRule(DetectLeaksAfterTestSuccess()).around(scenarioRule)!!

@Test fun togglesHelloAndGoodbye() {
inAnyView(withText("Hello"))
Expand Down

0 comments on commit 03ab545

Please sign in to comment.