android / sunflower

A gardening app illustrating Android development best practices with migrating a View-based app to Jetpack Compose.
https://d.android.com/jetpack
Apache License 2.0
17.66k stars 4.71k forks source link

clickAddPlant_OpensPlantList test fails on API 29 emulator #615

Open dturner opened 4 years ago

dturner commented 4 years ago

I get the following error when running clickAddPlant_OpensPlantList on the API 29 emulator:

06-04 14:14:09.144 10145 15538 15571 E TestRunner: failed: clickAddPlant_OpensPlantList(com.google.samples.apps.sunflower.GardenActivityTest)
06-04 14:14:09.146 10145 15538 15571 E TestRunner: ----- begin exception -----
06-04 14:14:09.148 10145 15538 15571 E TestRunner: androidx.test.espresso.PerformException: Error performing 'single click' on view 'with id: com.google.samples.apps.sunflower:id/add_plant'.
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at androidx.test.espresso.PerformException$Builder.build(PerformException.java:84)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at androidx.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:85)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at androidx.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:57)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at androidx.test.espresso.ViewInteraction.waitForAndHandleInteractionResults(ViewInteraction.java:316)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at androidx.test.espresso.ViewInteraction.desugaredPerform(ViewInteraction.java:177)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at androidx.test.espresso.ViewInteraction.perform(ViewInteraction.java:118)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at com.google.samples.apps.sunflower.GardenActivityTest.clickAddPlant_OpensPlantList(GardenActivityTest.kt:37)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at java.lang.reflect.Method.invoke(Native Method)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at androidx.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:531)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at org.junit.rules.RunRules.evaluate(RunRules.java:20)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at org.junit.runners.Suite.runChild(Suite.java:128)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at org.junit.runners.Suite.runChild(Suite.java:27)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:388)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2189)
06-04 14:14:09.148 10145 15538 15571 E TestRunner: Caused by: java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints:
06-04 14:14:09.148 10145 15538 15571 E TestRunner: at least 90 percent of the view's area is displayed to the user.
06-04 14:14:09.148 10145 15538 15571 E TestRunner: Target view: "MaterialButton{id=2131230790, res-name=add_plant, visibility=VISIBLE, width=324, height=132, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@9941497, tag=null, root-is-layout-requested=false, has-input-connection=false, x=378.0, y=882.0, text=Add plant, input-type=0, ime-target=false, has-links=false, is-checked=false}"
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at androidx.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:248)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at androidx.test.espresso.ViewInteraction.access$100(ViewInteraction.java:64)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at androidx.test.espresso.ViewInteraction$1.call(ViewInteraction.java:157)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at androidx.test.espresso.ViewInteraction$1.call(ViewInteraction.java:154)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at java.util.concurrent.FutureTask.run(FutureTask.java:266)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at android.os.Handler.handleCallback(Handler.java:883)
06-04 14:14:09.148 10145 15538 15571 E TestRunner:  at android.os.Handler.dispatchMessage(Han
06-04 14:14:09.148 10145 15538 15571 E TestRunner: ----- end exception -----
tiembo commented 4 years ago

Hey Don - thanks for the report. I think I figured out what's happening. If Sunflower is already installed on the emulator and if a plant exists in the garden, then the tests fails (as the "Add Plant" button is hidden). If the garden is empty or the app isn't installed, the test will pass.

Can you confirm that this is what you're seeing, too?

dturner commented 4 years ago

Hey Tiem - yep, that's it! :)

Looks like you need to instantiate GardenFragment with an empty database, rather than using the same one used by the app.

Interested to hear your thoughts on how to do this as I'm facing a similar testing scenario in another app.