chiuki / espresso-samples

A collection of samples demonstrating different Espresso techniques.
Apache License 2.0
635 stars 156 forks source link

Value of ElapsedTimeIdlingResource? #9

Open RobertLK opened 6 years ago

RobertLK commented 6 years ago

Been thinking a lot about this recently because I've seen it in a few projects and I'm struggling to see what it offers over a simple Thread.sleep. The only context I can find is this blog post, which simply states "We could use SystemClock.sleep(60000), but that blocks the testing thread.". This is a strange justification since IdlingResources cause onView and onIdle to block the testing thread and this is wanted and expected behaviour for test code (tests are always run synchronously). As far as I can tell using this IdlingResource is identical to using a sleep from a thread execution standpoint, but the code is more verbose and harder to understand. This seems to me like a misuse of IdlingResource and a testing anti-pattern, and it seems to be used in many codebases where a sleep would be simpler. Please let me know if there's some other execution property that makes this implementation advantageous. Thanks.

chiuki commented 6 years ago

I agree with you. I wrote ElapsedTimeIdlingResource mostly as an exercise to understand how idling resources work, and there is no real use case. I wish I can retract it but it's been a few years so I'm not sure what's the best way to deal with it.

RobertLK commented 6 years ago

Thanks for replying Definitely tricky with so many people using it, but it's not a big problem if they've got it working and they're happy. This is still a common challenge new developers face though, and this repo comes high in search results, so adding more context here could be helpful. Just a note in the code or readme to say that using sleep is usually fine and may be the cleanest solution could save some confusion. Up to you though, certainly not a major issue. 😎

On Fri, 17 Aug 2018, 18:51 Chiu-Ki Chan, notifications@github.com wrote:

I agree with you. I wrote ElapsedTimeIdlingResource mostly as an exercise to understand how idling resources work, and there is no real use case. I wish I can retract it but it's been a few years so I'm not sure what's the best way to deal with it.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/chiuki/espresso-samples/issues/9#issuecomment-413941184, or mute the thread https://github.com/notifications/unsubscribe-auth/AL7A1qryL3w-_bJmFQJ3iaM_xsqo4TToks5uRwKEgaJpZM4WB68B .