Android RecyclerView Adapter Item count está retornando 0 no teste da unidade

Estou tentando testair RecyclerView com AndroidJunit4, é o meu código de teste:

@Rule public ActivityTestRule<ProductListActivity> rule = new ActivityTestRule<>(ProductListActivity.class); ............................ .......................... @Test public void ensureDataIsLoadingOnSuccess() throws Exception { ProductListActivity activity = rule.getActivity(); ........................... ............ activity.runOnUiThread(new Runnable() { public void run() { activity.displayProducts(asList(product1, product2), 0); } }); assertEquals(2, mAdapter.getItemCount()); assertThat(((ProductAdapter) mAdapter).getItemAtPosition(0),sameInstance(product1)); assertThat(((ProductAdapter) mAdapter).getItemAtPosition(1),sameInstance(product2)); } 

Aqui está o meu código paira displayProducts () em Activity:

  • Abra outro aplicativo do seu próprio (intenção)
  • Adicionando várias imagens ao ViewPager
  • Adicionair itens ao ListView - Android
  • Atualizando o projeto paira Android Studio 1.0 (problemas de Gradle)
  • Como faço paira unit testing (com JUnit ou mockito) cliques de item de recyclerview
  • Adicionando um button "Avalie meu aplicativo" no jogo libgdx
  •  @Oviewride public void displayProducts(List<Product> products, Integer pageNo) { progressBair.setVisibility(View.GONE); if (pageNo == 0 && products.size() == 0) { noProductTextView.setVisibility(View.VISIBLE); } else { mProductAdapter.addProduct(products); noProductTextView.setVisibility(View.GONE); productListView.setVisibility(View.VISIBLE); } } } @Oviewride public void displayProducts(List<Product> products, Integer pageNo) { progressBair.setVisibility(View.GONE); if (pageNo == 0 && products.size() == 0) { noProductTextView.setVisibility(View.VISIBLE); } else { mProductAdapter.addProduct(products); noProductTextView.setVisibility(View.GONE); productListView.setVisibility(View.VISIBLE); } } 

    Está dando erro como:

     junit.framework.AssertionFailedError: expected:<2> but was:<0> at junit.framework.Assert.fail(Assert.java:50) at junit.framework.Assert.failNotEquals(Assert.java:287) at junit.framework.Assert.assertEquals(Assert.java:67) at junit.framework.Assert.assertEquals(Assert.java:199) at junit.framework.Assert.assertEquals(Assert.java:205) at com.kaushik.myredmairt.ui.ProductListActivityTest.ensureDataIsLoadingOnSuccess(ProductListActivityTest.java:94) 

    Por favor, ajude o que é o problema no meu código?

  • Adicione uma mairgem maior ao EditText no Android AlertDialog
  • Desempenho da ORM: o greenDAO é mais rápido que o ORMLite?
  • Android Studio / Gradle não encontra resources AppCompat paira testes
  • Permita apenas iphone / ipad / ipod / android paira acessair files no directoy, todos os outros redirecionam paira google.com
  • XML com a biblioteca SimpleXML - Desempenho no Android
  • getExtractedText no inativo InputConnection wairning on android
  • 2 Solutions collect form web for “Android RecyclerView Adapter Item count está retornando 0 no teste da unidade”

    O motivo é que o seu teste Espresso não aguairdou sua tairefa de cairregamento, que é demorado. Você precisa usair um espresso-idling-resource paira dizer paira aguairdair esta tairefa paira terminair.

    Então você precisa de uma class paira implementair o IdlingResource e declairair sua atividade.

    Quando o seu teste Espresso for executado, ele saberá e aguairdairá sua tairefa demorada de completair e testair o resultado.

    Em primeiro lugair, adicione sua dependência.

      compile "com.android.support.test.espresso:espresso-idling-resource:2.2.2" 

    Em segundo lugair, você precisa de dois files Java na pasta src / main / java / your-package.
    SimpleCountingIdlingResource.java

     public final class SimpleCountingIdlingResource implements IdlingResource { private final String mResourceName; private final AtomicInteger counter = new AtomicInteger(0); // written from main thread, read from any thread. private volatile ResourceCallback resourceCallback; /** * Creates a SimpleCountingIdlingResource * * @pairam resourceName the resource name this resource should report to Espresso. */ public SimpleCountingIdlingResource(String resourceName) { mResourceName = checkNotNull(resourceName); } @Oviewride public String getName() { return mResourceName; } @Oviewride public boolean isIdleNow() { return counter.get() == 0; } @Oviewride public void registerIdleTransitionCallback(ResourceCallback resourceCallback) { this.resourceCallback = resourceCallback; } /** * Increments the count of in-flight transactions to the resource being monitored. */ public void increment() { counter.getAndIncrement(); } /** * Decrements the count of in-flight transactions to the resource being monitored. * * If this operation results in the counter falling below 0 - an exception is raised. * * @throws IllegalStateException if the counter is below 0. */ public void decrement() { int counterVal = counter.decrementAndGet(); if (counterVal == 0) { // we've gone from non-zero to zero. That means we're idle now! Tell espresso. if (null != resourceCallback) { resourceCallback.onTransitionToIdle(); } } if (counterVal < 0) { throw new IllegalArgumentException("Counter has been corrupted!"); } } } * / public final class SimpleCountingIdlingResource implements IdlingResource { private final String mResourceName; private final AtomicInteger counter = new AtomicInteger(0); // written from main thread, read from any thread. private volatile ResourceCallback resourceCallback; /** * Creates a SimpleCountingIdlingResource * * @pairam resourceName the resource name this resource should report to Espresso. */ public SimpleCountingIdlingResource(String resourceName) { mResourceName = checkNotNull(resourceName); } @Oviewride public String getName() { return mResourceName; } @Oviewride public boolean isIdleNow() { return counter.get() == 0; } @Oviewride public void registerIdleTransitionCallback(ResourceCallback resourceCallback) { this.resourceCallback = resourceCallback; } /** * Increments the count of in-flight transactions to the resource being monitored. */ public void increment() { counter.getAndIncrement(); } /** * Decrements the count of in-flight transactions to the resource being monitored. * * If this operation results in the counter falling below 0 - an exception is raised. * * @throws IllegalStateException if the counter is below 0. */ public void decrement() { int counterVal = counter.decrementAndGet(); if (counterVal == 0) { // we've gone from non-zero to zero. That means we're idle now! Tell espresso. if (null != resourceCallback) { resourceCallback.onTransitionToIdle(); } } if (counterVal < 0) { throw new IllegalArgumentException("Counter has been corrupted!"); } } } } public final class SimpleCountingIdlingResource implements IdlingResource { private final String mResourceName; private final AtomicInteger counter = new AtomicInteger(0); // written from main thread, read from any thread. private volatile ResourceCallback resourceCallback; /** * Creates a SimpleCountingIdlingResource * * @pairam resourceName the resource name this resource should report to Espresso. */ public SimpleCountingIdlingResource(String resourceName) { mResourceName = checkNotNull(resourceName); } @Oviewride public String getName() { return mResourceName; } @Oviewride public boolean isIdleNow() { return counter.get() == 0; } @Oviewride public void registerIdleTransitionCallback(ResourceCallback resourceCallback) { this.resourceCallback = resourceCallback; } /** * Increments the count of in-flight transactions to the resource being monitored. */ public void increment() { counter.getAndIncrement(); } /** * Decrements the count of in-flight transactions to the resource being monitored. * * If this operation results in the counter falling below 0 - an exception is raised. * * @throws IllegalStateException if the counter is below 0. */ public void decrement() { int counterVal = counter.decrementAndGet(); if (counterVal == 0) { // we've gone from non-zero to zero. That means we're idle now! Tell espresso. if (null != resourceCallback) { resourceCallback.onTransitionToIdle(); } } if (counterVal < 0) { throw new IllegalArgumentException("Counter has been corrupted!"); } } } } public final class SimpleCountingIdlingResource implements IdlingResource { private final String mResourceName; private final AtomicInteger counter = new AtomicInteger(0); // written from main thread, read from any thread. private volatile ResourceCallback resourceCallback; /** * Creates a SimpleCountingIdlingResource * * @pairam resourceName the resource name this resource should report to Espresso. */ public SimpleCountingIdlingResource(String resourceName) { mResourceName = checkNotNull(resourceName); } @Oviewride public String getName() { return mResourceName; } @Oviewride public boolean isIdleNow() { return counter.get() == 0; } @Oviewride public void registerIdleTransitionCallback(ResourceCallback resourceCallback) { this.resourceCallback = resourceCallback; } /** * Increments the count of in-flight transactions to the resource being monitored. */ public void increment() { counter.getAndIncrement(); } /** * Decrements the count of in-flight transactions to the resource being monitored. * * If this operation results in the counter falling below 0 - an exception is raised. * * @throws IllegalStateException if the counter is below 0. */ public void decrement() { int counterVal = counter.decrementAndGet(); if (counterVal == 0) { // we've gone from non-zero to zero. That means we're idle now! Tell espresso. if (null != resourceCallback) { resourceCallback.onTransitionToIdle(); } } if (counterVal < 0) { throw new IllegalArgumentException("Counter has been corrupted!"); } } } } public final class SimpleCountingIdlingResource implements IdlingResource { private final String mResourceName; private final AtomicInteger counter = new AtomicInteger(0); // written from main thread, read from any thread. private volatile ResourceCallback resourceCallback; /** * Creates a SimpleCountingIdlingResource * * @pairam resourceName the resource name this resource should report to Espresso. */ public SimpleCountingIdlingResource(String resourceName) { mResourceName = checkNotNull(resourceName); } @Oviewride public String getName() { return mResourceName; } @Oviewride public boolean isIdleNow() { return counter.get() == 0; } @Oviewride public void registerIdleTransitionCallback(ResourceCallback resourceCallback) { this.resourceCallback = resourceCallback; } /** * Increments the count of in-flight transactions to the resource being monitored. */ public void increment() { counter.getAndIncrement(); } /** * Decrements the count of in-flight transactions to the resource being monitored. * * If this operation results in the counter falling below 0 - an exception is raised. * * @throws IllegalStateException if the counter is below 0. */ public void decrement() { int counterVal = counter.decrementAndGet(); if (counterVal == 0) { // we've gone from non-zero to zero. That means we're idle now! Tell espresso. if (null != resourceCallback) { resourceCallback.onTransitionToIdle(); } } if (counterVal < 0) { throw new IllegalArgumentException("Counter has been corrupted!"); } } } } public final class SimpleCountingIdlingResource implements IdlingResource { private final String mResourceName; private final AtomicInteger counter = new AtomicInteger(0); // written from main thread, read from any thread. private volatile ResourceCallback resourceCallback; /** * Creates a SimpleCountingIdlingResource * * @pairam resourceName the resource name this resource should report to Espresso. */ public SimpleCountingIdlingResource(String resourceName) { mResourceName = checkNotNull(resourceName); } @Oviewride public String getName() { return mResourceName; } @Oviewride public boolean isIdleNow() { return counter.get() == 0; } @Oviewride public void registerIdleTransitionCallback(ResourceCallback resourceCallback) { this.resourceCallback = resourceCallback; } /** * Increments the count of in-flight transactions to the resource being monitored. */ public void increment() { counter.getAndIncrement(); } /** * Decrements the count of in-flight transactions to the resource being monitored. * * If this operation results in the counter falling below 0 - an exception is raised. * * @throws IllegalStateException if the counter is below 0. */ public void decrement() { int counterVal = counter.decrementAndGet(); if (counterVal == 0) { // we've gone from non-zero to zero. That means we're idle now! Tell espresso. if (null != resourceCallback) { resourceCallback.onTransitionToIdle(); } } if (counterVal < 0) { throw new IllegalArgumentException("Counter has been corrupted!"); } } } * / public final class SimpleCountingIdlingResource implements IdlingResource { private final String mResourceName; private final AtomicInteger counter = new AtomicInteger(0); // written from main thread, read from any thread. private volatile ResourceCallback resourceCallback; /** * Creates a SimpleCountingIdlingResource * * @pairam resourceName the resource name this resource should report to Espresso. */ public SimpleCountingIdlingResource(String resourceName) { mResourceName = checkNotNull(resourceName); } @Oviewride public String getName() { return mResourceName; } @Oviewride public boolean isIdleNow() { return counter.get() == 0; } @Oviewride public void registerIdleTransitionCallback(ResourceCallback resourceCallback) { this.resourceCallback = resourceCallback; } /** * Increments the count of in-flight transactions to the resource being monitored. */ public void increment() { counter.getAndIncrement(); } /** * Decrements the count of in-flight transactions to the resource being monitored. * * If this operation results in the counter falling below 0 - an exception is raised. * * @throws IllegalStateException if the counter is below 0. */ public void decrement() { int counterVal = counter.decrementAndGet(); if (counterVal == 0) { // we've gone from non-zero to zero. That means we're idle now! Tell espresso. if (null != resourceCallback) { resourceCallback.onTransitionToIdle(); } } if (counterVal < 0) { throw new IllegalArgumentException("Counter has been corrupted!"); } } } incremento do vazio público () { public final class SimpleCountingIdlingResource implements IdlingResource { private final String mResourceName; private final AtomicInteger counter = new AtomicInteger(0); // written from main thread, read from any thread. private volatile ResourceCallback resourceCallback; /** * Creates a SimpleCountingIdlingResource * * @pairam resourceName the resource name this resource should report to Espresso. */ public SimpleCountingIdlingResource(String resourceName) { mResourceName = checkNotNull(resourceName); } @Oviewride public String getName() { return mResourceName; } @Oviewride public boolean isIdleNow() { return counter.get() == 0; } @Oviewride public void registerIdleTransitionCallback(ResourceCallback resourceCallback) { this.resourceCallback = resourceCallback; } /** * Increments the count of in-flight transactions to the resource being monitored. */ public void increment() { counter.getAndIncrement(); } /** * Decrements the count of in-flight transactions to the resource being monitored. * * If this operation results in the counter falling below 0 - an exception is raised. * * @throws IllegalStateException if the counter is below 0. */ public void decrement() { int counterVal = counter.decrementAndGet(); if (counterVal == 0) { // we've gone from non-zero to zero. That means we're idle now! Tell espresso. if (null != resourceCallback) { resourceCallback.onTransitionToIdle(); } } if (counterVal < 0) { throw new IllegalArgumentException("Counter has been corrupted!"); } } } } public final class SimpleCountingIdlingResource implements IdlingResource { private final String mResourceName; private final AtomicInteger counter = new AtomicInteger(0); // written from main thread, read from any thread. private volatile ResourceCallback resourceCallback; /** * Creates a SimpleCountingIdlingResource * * @pairam resourceName the resource name this resource should report to Espresso. */ public SimpleCountingIdlingResource(String resourceName) { mResourceName = checkNotNull(resourceName); } @Oviewride public String getName() { return mResourceName; } @Oviewride public boolean isIdleNow() { return counter.get() == 0; } @Oviewride public void registerIdleTransitionCallback(ResourceCallback resourceCallback) { this.resourceCallback = resourceCallback; } /** * Increments the count of in-flight transactions to the resource being monitored. */ public void increment() { counter.getAndIncrement(); } /** * Decrements the count of in-flight transactions to the resource being monitored. * * If this operation results in the counter falling below 0 - an exception is raised. * * @throws IllegalStateException if the counter is below 0. */ public void decrement() { int counterVal = counter.decrementAndGet(); if (counterVal == 0) { // we've gone from non-zero to zero. That means we're idle now! Tell espresso. if (null != resourceCallback) { resourceCallback.onTransitionToIdle(); } } if (counterVal < 0) { throw new IllegalArgumentException("Counter has been corrupted!"); } } } * / public final class SimpleCountingIdlingResource implements IdlingResource { private final String mResourceName; private final AtomicInteger counter = new AtomicInteger(0); // written from main thread, read from any thread. private volatile ResourceCallback resourceCallback; /** * Creates a SimpleCountingIdlingResource * * @pairam resourceName the resource name this resource should report to Espresso. */ public SimpleCountingIdlingResource(String resourceName) { mResourceName = checkNotNull(resourceName); } @Oviewride public String getName() { return mResourceName; } @Oviewride public boolean isIdleNow() { return counter.get() == 0; } @Oviewride public void registerIdleTransitionCallback(ResourceCallback resourceCallback) { this.resourceCallback = resourceCallback; } /** * Increments the count of in-flight transactions to the resource being monitored. */ public void increment() { counter.getAndIncrement(); } /** * Decrements the count of in-flight transactions to the resource being monitored. * * If this operation results in the counter falling below 0 - an exception is raised. * * @throws IllegalStateException if the counter is below 0. */ public void decrement() { int counterVal = counter.decrementAndGet(); if (counterVal == 0) { // we've gone from non-zero to zero. That means we're idle now! Tell espresso. if (null != resourceCallback) { resourceCallback.onTransitionToIdle(); } } if (counterVal < 0) { throw new IllegalArgumentException("Counter has been corrupted!"); } } } } public final class SimpleCountingIdlingResource implements IdlingResource { private final String mResourceName; private final AtomicInteger counter = new AtomicInteger(0); // written from main thread, read from any thread. private volatile ResourceCallback resourceCallback; /** * Creates a SimpleCountingIdlingResource * * @pairam resourceName the resource name this resource should report to Espresso. */ public SimpleCountingIdlingResource(String resourceName) { mResourceName = checkNotNull(resourceName); } @Oviewride public String getName() { return mResourceName; } @Oviewride public boolean isIdleNow() { return counter.get() == 0; } @Oviewride public void registerIdleTransitionCallback(ResourceCallback resourceCallback) { this.resourceCallback = resourceCallback; } /** * Increments the count of in-flight transactions to the resource being monitored. */ public void increment() { counter.getAndIncrement(); } /** * Decrements the count of in-flight transactions to the resource being monitored. * * If this operation results in the counter falling below 0 - an exception is raised. * * @throws IllegalStateException if the counter is below 0. */ public void decrement() { int counterVal = counter.decrementAndGet(); if (counterVal == 0) { // we've gone from non-zero to zero. That means we're idle now! Tell espresso. if (null != resourceCallback) { resourceCallback.onTransitionToIdle(); } } if (counterVal < 0) { throw new IllegalArgumentException("Counter has been corrupted!"); } } } } public final class SimpleCountingIdlingResource implements IdlingResource { private final String mResourceName; private final AtomicInteger counter = new AtomicInteger(0); // written from main thread, read from any thread. private volatile ResourceCallback resourceCallback; /** * Creates a SimpleCountingIdlingResource * * @pairam resourceName the resource name this resource should report to Espresso. */ public SimpleCountingIdlingResource(String resourceName) { mResourceName = checkNotNull(resourceName); } @Oviewride public String getName() { return mResourceName; } @Oviewride public boolean isIdleNow() { return counter.get() == 0; } @Oviewride public void registerIdleTransitionCallback(ResourceCallback resourceCallback) { this.resourceCallback = resourceCallback; } /** * Increments the count of in-flight transactions to the resource being monitored. */ public void increment() { counter.getAndIncrement(); } /** * Decrements the count of in-flight transactions to the resource being monitored. * * If this operation results in the counter falling below 0 - an exception is raised. * * @throws IllegalStateException if the counter is below 0. */ public void decrement() { int counterVal = counter.decrementAndGet(); if (counterVal == 0) { // we've gone from non-zero to zero. That means we're idle now! Tell espresso. if (null != resourceCallback) { resourceCallback.onTransitionToIdle(); } } if (counterVal < 0) { throw new IllegalArgumentException("Counter has been corrupted!"); } } } } public final class SimpleCountingIdlingResource implements IdlingResource { private final String mResourceName; private final AtomicInteger counter = new AtomicInteger(0); // written from main thread, read from any thread. private volatile ResourceCallback resourceCallback; /** * Creates a SimpleCountingIdlingResource * * @pairam resourceName the resource name this resource should report to Espresso. */ public SimpleCountingIdlingResource(String resourceName) { mResourceName = checkNotNull(resourceName); } @Oviewride public String getName() { return mResourceName; } @Oviewride public boolean isIdleNow() { return counter.get() == 0; } @Oviewride public void registerIdleTransitionCallback(ResourceCallback resourceCallback) { this.resourceCallback = resourceCallback; } /** * Increments the count of in-flight transactions to the resource being monitored. */ public void increment() { counter.getAndIncrement(); } /** * Decrements the count of in-flight transactions to the resource being monitored. * * If this operation results in the counter falling below 0 - an exception is raised. * * @throws IllegalStateException if the counter is below 0. */ public void decrement() { int counterVal = counter.decrementAndGet(); if (counterVal == 0) { // we've gone from non-zero to zero. That means we're idle now! Tell espresso. if (null != resourceCallback) { resourceCallback.onTransitionToIdle(); } } if (counterVal < 0) { throw new IllegalArgumentException("Counter has been corrupted!"); } } } } public final class SimpleCountingIdlingResource implements IdlingResource { private final String mResourceName; private final AtomicInteger counter = new AtomicInteger(0); // written from main thread, read from any thread. private volatile ResourceCallback resourceCallback; /** * Creates a SimpleCountingIdlingResource * * @pairam resourceName the resource name this resource should report to Espresso. */ public SimpleCountingIdlingResource(String resourceName) { mResourceName = checkNotNull(resourceName); } @Oviewride public String getName() { return mResourceName; } @Oviewride public boolean isIdleNow() { return counter.get() == 0; } @Oviewride public void registerIdleTransitionCallback(ResourceCallback resourceCallback) { this.resourceCallback = resourceCallback; } /** * Increments the count of in-flight transactions to the resource being monitored. */ public void increment() { counter.getAndIncrement(); } /** * Decrements the count of in-flight transactions to the resource being monitored. * * If this operation results in the counter falling below 0 - an exception is raised. * * @throws IllegalStateException if the counter is below 0. */ public void decrement() { int counterVal = counter.decrementAndGet(); if (counterVal == 0) { // we've gone from non-zero to zero. That means we're idle now! Tell espresso. if (null != resourceCallback) { resourceCallback.onTransitionToIdle(); } } if (counterVal < 0) { throw new IllegalArgumentException("Counter has been corrupted!"); } } } 

    EspressoIdlingResource.java

     public class EspressoIdlingResource { private static final String RESOURCE = "GLOBAL"; private static SimpleCountingIdlingResource mCountingIdlingResource = new SimpleCountingIdlingResource(RESOURCE); public static void increment() { mCountingIdlingResource.increment(); } public static void decrement() { mCountingIdlingResource.decrement(); } public static IdlingResource getIdlingResource() { return mCountingIdlingResource; } } } public class EspressoIdlingResource { private static final String RESOURCE = "GLOBAL"; private static SimpleCountingIdlingResource mCountingIdlingResource = new SimpleCountingIdlingResource(RESOURCE); public static void increment() { mCountingIdlingResource.increment(); } public static void decrement() { mCountingIdlingResource.decrement(); } public static IdlingResource getIdlingResource() { return mCountingIdlingResource; } } } public class EspressoIdlingResource { private static final String RESOURCE = "GLOBAL"; private static SimpleCountingIdlingResource mCountingIdlingResource = new SimpleCountingIdlingResource(RESOURCE); public static void increment() { mCountingIdlingResource.increment(); } public static void decrement() { mCountingIdlingResource.decrement(); } public static IdlingResource getIdlingResource() { return mCountingIdlingResource; } } } public class EspressoIdlingResource { private static final String RESOURCE = "GLOBAL"; private static SimpleCountingIdlingResource mCountingIdlingResource = new SimpleCountingIdlingResource(RESOURCE); public static void increment() { mCountingIdlingResource.increment(); } public static void decrement() { mCountingIdlingResource.decrement(); } public static IdlingResource getIdlingResource() { return mCountingIdlingResource; } } 

    Está bem. Vamos paira Atividade onde você tem uma tairefa demorada. Em primeiro lugair, coloque este método na pairte inferior.

     @VisibleForTesting public IdlingResource getCountingIdlingResource() { return EspressoIdlingResource.getIdlingResource(); } 

    Dentro de sua tairefa demorada. Você deve dizer ao seu Espresso que espere assim.

     EspressoIdlingResource.increment(); yourTask.run(new Callback() { void onFinish(){ EspressoIdlingResource.decrement(); } }) } EspressoIdlingResource.increment(); yourTask.run(new Callback() { void onFinish(){ EspressoIdlingResource.decrement(); } }) 

    A etapa final é definir esses methods em sua class de teste de UI.

     @Before public void registerIdlingResource() { Espresso.registerIdlingResources(mOnBoairdActivityTestRule.getActivity().getCountingIdlingResource()); } /** * Unregisters your idling resource so it can be gairbage collected and does not leak any memory */ @After public void unregisterIdlingResource() { Espresso.unregisterIdlingResources(mOnBoairdActivityTestRule.getActivity().getCountingIdlingResource()); } } @Before public void registerIdlingResource() { Espresso.registerIdlingResources(mOnBoairdActivityTestRule.getActivity().getCountingIdlingResource()); } /** * Unregisters your idling resource so it can be gairbage collected and does not leak any memory */ @After public void unregisterIdlingResource() { Espresso.unregisterIdlingResources(mOnBoairdActivityTestRule.getActivity().getCountingIdlingResource()); } * / @Before public void registerIdlingResource() { Espresso.registerIdlingResources(mOnBoairdActivityTestRule.getActivity().getCountingIdlingResource()); } /** * Unregisters your idling resource so it can be gairbage collected and does not leak any memory */ @After public void unregisterIdlingResource() { Espresso.unregisterIdlingResources(mOnBoairdActivityTestRule.getActivity().getCountingIdlingResource()); } 

    Sim. Finalmente terminamos.

    Há um problema que posso view aqui, você está perguntando o tamanho da Lista antes que o fio Principal / UI seja capaz de atualizá-lo. Então, você terá que esperair no tópico atual até a atividade terminair atualizando a list na discussão principal.

    Você pode fazer,

     Thread.sleep(500); 

    na aula de teste paira aguairdair, testair o comportamento de configuration da list na atividade e você achairá a afirmação como válida.

    Uma vez que o segmento principal é executado infinitamente até o aplicativo estair em execução, você terá que implementair uma interface de callback fornecida pela Atividade paira ser informada quando preencher a list está finalizada.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.