osama-raddad/android-test-kit

Add Espresso.unregisterIdlingResource() API

Closed this issue · 5 comments

What steps will reproduce the problem?
1. Call Espresso.registerIdlingResource(idlingResource) in the setUp() method 
of your test class
2. Run your tests

What is the expected output? 
A new instance of the supplied idling resource to be registered

What do you see instead?
Espresso ignores the new instance if an instance that returns the same value 
for IdlingResource.getName() is already registered

What version of the product are you using?
Espresso 1.1

Please provide any additional information below.
I am in a situation where the idling resource needs to have a reference to a 
component in the current context, i.e. it needs a reference to a particular 
view in the view hierarchy: if the idling resource is created and registered 
the first time on setup and it has a reference to a component in the current 
context, Espresso will keep the very first reference and all successive tests 
will be compromised. Moreover, this causes a memory leak. What I'm currently 
doing is far from ideal: instantiate all idling resources and register them in 
a static block, register an activity lifecycle callback, inject in the idling 
resource the components tied to the current context when the activity under 
test is created and remove the reference to those components when the activity 
is destroyed. But this approach is clunky and error prone. A new 
Espresso.unregisterIdlingResource(idlingResource) API would make this case way 
easier.

Original issue reported on code.google.com by stefano....@gmail.com on 2 Apr 2014 at 9:56

Original comment by vale...@google.com on 7 May 2014 at 7:14

  • Changed state: Accepted
[deleted comment]
Is there any update to this? It really makes sense to be able to clean them up.

A nice option would be to have one-shot idle resources, meaning that you 
register them, and they get unregistered as soon as they hit idle (Good for 
when you just want to sync until something finishes loading, and after that 
loads that reource won't be doing extra job any more).

For now I suppose the only "work-around" is to provide "pseudo-random" names so 
espresso doesn't discard the new ones, or preparing a framework where your idle 
resource contains actually several of those, and implementing the methods as an 
aggregate of the contained idle resources (Kinda like an "idle resource pool" 
which is similar to what the system is doing on a higher level I suppose).

Original comment by sergio.t...@corp.badoo.com on 28 Nov 2014 at 10:45

Unregistering will be included in the next Espresso release (don't know when 
that will be though)

Original comment by stefano....@jimdo.com on 28 Nov 2014 at 12:32

Fixed in Espresso 2.0

Original comment by vale...@google.com on 20 Dec 2014 at 4:33

  • Changed state: Fixed