Skip to content

Commit

Permalink
wrap Activity and Compose rules in LeakCanary checks on both sides
Browse files Browse the repository at this point in the history
fixes #657
  • Loading branch information
RBusarow committed Apr 19, 2022
1 parent 15bbeea commit 5b404c2
Show file tree
Hide file tree
Showing 28 changed files with 100 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import androidx.compose.ui.test.onNodeWithText
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.DetectLeaksAfterTestSuccess
import com.squareup.workflow1.ui.internal.test.IdleAfterTestRule
import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule
import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
Expand All @@ -19,10 +19,10 @@ import org.junit.runner.RunWith
class HelloComposeTest {

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

@Test fun togglesBetweenStates() {
composeRule.onNodeWithText("Hello")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import androidx.compose.ui.test.onNodeWithText
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.DetectLeaksAfterTestSuccess
import com.squareup.workflow1.ui.internal.test.IdleAfterTestRule
import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule
import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
Expand All @@ -19,10 +19,10 @@ import org.junit.runner.RunWith
class HelloBindingTest {

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

@Test fun togglesBetweenStates() {
composeRule.onNodeWithText("Hello")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import androidx.compose.ui.test.onNodeWithText
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.DetectLeaksAfterTestSuccess
import com.squareup.workflow1.ui.internal.test.IdleAfterTestRule
import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule
import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
Expand All @@ -19,10 +19,10 @@ import org.junit.runner.RunWith
class HelloComposeWorkflowTest {

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

@Test fun togglesBetweenStates() {
composeRule.onNodeWithText("Hello")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import androidx.compose.ui.test.junit4.createAndroidComposeRule
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.DetectLeaksAfterTestSuccess
import com.squareup.workflow1.ui.internal.test.IdleAfterTestRule
import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule
import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
Expand All @@ -20,10 +20,10 @@ import org.junit.runner.RunWith
class InlineRenderingTest {

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

@Test fun counterIncrements() {
composeRule.onNode(hasClickAction())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
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.DetectLeaksAfterTestSuccess
import com.squareup.workflow1.ui.internal.test.IdleAfterTestRule
import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule
import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
Expand All @@ -25,10 +25,10 @@ import org.junit.runner.RunWith
class SampleLauncherTest {

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

@OptIn(ExperimentalTestApi::class)
@Test fun allSamplesLaunch() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import androidx.compose.ui.test.onNodeWithText
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.DetectLeaksAfterTestSuccess
import com.squareup.workflow1.ui.internal.test.IdleAfterTestRule
import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule
import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
Expand All @@ -25,10 +25,10 @@ private const val ADD_BUTTON_TEXT = "Add Child"
class NestedRenderingsTest {

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

@Test fun childrenAreAddedAndRemoved() {
composeRule.onNodeWithText(ADD_BUTTON_TEXT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import androidx.compose.ui.test.junit4.createAndroidComposeRule
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.DetectLeaksAfterTestSuccess
import com.squareup.workflow1.ui.internal.test.IdleAfterTestRule
import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule
import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
Expand All @@ -19,10 +19,10 @@ import org.junit.runner.RunWith
class PreviewTest {

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

@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 @@ -10,9 +10,9 @@ import androidx.compose.ui.test.performTextInput
import androidx.compose.ui.test.performTextReplacement
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import com.squareup.workflow1.ui.internal.test.DetectLeaksAfterTestSuccess
import com.squareup.workflow1.ui.internal.test.IdleAfterTestRule
import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule
import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
Expand All @@ -23,10 +23,10 @@ import org.junit.runner.RunWith
class TextInputTest {

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

@OptIn(ExperimentalTestApi::class)
@Test fun allowsTextEditing() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import androidx.test.ext.junit.rules.ActivityScenarioRule
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.DetectLeaksAfterTestSuccess
import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule
import com.squareup.workflow1.ui.internal.test.inAnyView
import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
Expand All @@ -20,9 +20,9 @@ import org.junit.runner.RunWith
class PoetryAppTest {

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

@Test fun launches() {
inAnyView(withText(R.string.poems))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import androidx.test.espresso.matcher.ViewMatchers.withText
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.DetectLeaksAfterTestSuccess
import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule
import com.squareup.workflow1.ui.internal.test.inAnyView
import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
Expand All @@ -19,9 +19,9 @@ import org.junit.runner.RunWith
class RavenAppTest {

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

@Test fun launches() {
inAnyView(withText("The Raven"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import androidx.test.espresso.matcher.ViewMatchers.withText
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.DetectLeaksAfterTestSuccess
import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule
import com.squareup.workflow1.ui.internal.test.actuallyPressBack
import com.squareup.workflow1.ui.internal.test.inAnyView
import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
Expand All @@ -22,9 +22,9 @@ import org.junit.runner.RunWith
class HelloBackButtonEspressoTest {

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

@Test fun wrappedTakesPrecedence() {
inAnyView(withId(R.id.hello_message)).apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import androidx.test.espresso.matcher.ViewMatchers.withText
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.DetectLeaksAfterTestSuccess
import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule
import com.squareup.workflow1.ui.internal.test.inAnyView
import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
Expand All @@ -19,9 +19,9 @@ import org.junit.runner.RunWith
class DungeonAppTest {

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

@Test fun loadsBoardsList() {
inAnyView(withText(R.string.boards_list_label))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import androidx.test.espresso.matcher.ViewMatchers.withText
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.DetectLeaksAfterTestSuccess
import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule
import com.squareup.workflow1.ui.internal.test.inAnyView
import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary
import org.hamcrest.Matchers.containsString
import org.junit.Rule
import org.junit.Test
Expand All @@ -21,9 +21,9 @@ import org.junit.runner.RunWith
class HelloWorkflowFragmentAppTest {

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

@Test fun togglesHelloAndGoodbye() {
inAnyView(withText(containsString("Hello")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import androidx.test.espresso.matcher.ViewMatchers.withText
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.DetectLeaksAfterTestSuccess
import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule
import com.squareup.workflow1.ui.internal.test.inAnyView
import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
Expand All @@ -20,9 +20,9 @@ import org.junit.runner.RunWith
class HelloWorkflowAppTest {

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

@Test fun togglesHelloAndGoodbye() {
inAnyView(withText("Hello"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import androidx.test.espresso.matcher.ViewMatchers.withText
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.DetectLeaksAfterTestSuccess
import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule
import com.squareup.workflow1.ui.internal.test.inAnyView
import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary
import org.hamcrest.CoreMatchers.not
import org.junit.Rule
import org.junit.Test
Expand All @@ -22,9 +22,9 @@ import org.junit.runner.RunWith
internal class StubVisibilityAppTest {

private val scenarioRule = ActivityScenarioRule(StubVisibilityActivity::class.java)
@get:Rule val rules = RuleChain.outerRule(DetectLeaksAfterTestSuccess())
.around(scenarioRule)
@get:Rule val rules = RuleChain.outerRule(scenarioRule)
.around(IdlingDispatcherRule)
.wrapInLeakCanary()

@Test fun togglesFooter() {
inAnyView(withId(R.id.should_be_wrapped))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ import com.squareup.workflow1.ui.ViewEnvironment
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import com.squareup.workflow1.ui.environment
import com.squareup.workflow1.ui.getRendering
import com.squareup.workflow1.ui.internal.test.DetectLeaksAfterTestSuccess
import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule
import com.squareup.workflow1.ui.internal.test.actuallyPressBack
import com.squareup.workflow1.ui.internal.test.inAnyView
import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary
import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.CoreMatchers.endsWith
import org.junit.After
Expand All @@ -52,9 +52,9 @@ import java.util.concurrent.atomic.AtomicReference
class TicTacToeEspressoTest {

private val scenarioRule = ActivityScenarioRule(TicTacToeActivity::class.java)
@get:Rule val rules = RuleChain.outerRule(DetectLeaksAfterTestSuccess())
.around(scenarioRule)
@get:Rule val rules = RuleChain.outerRule(scenarioRule)
.around(IdlingDispatcherRule)
.wrapInLeakCanary()
private val scenario get() = scenarioRule.scenario

@Before
Expand Down
Loading

0 comments on commit 5b404c2

Please sign in to comment.