risangprisaltomo / android-test-kit

Automatically exported from code.google.com/p/android-test-kit
0 stars 0 forks source link

Multiple calls to a helper function containing onData will yield inconsistent results #82

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Created a helper method for performing taps to a button.

public void performFavoritesSelection(int photoIndex, int buttonId) throws 
InterruptedException{
        onData(anything())
                .inAdapterView(withId(android.R.id.list))
                .atPosition(photoIndex)
                .onChildView(withId(buttonId))
                .perform(click());
    }
2. In the test method, call this helper function multiple times.

public void testPickFavorites() throws InterruptedException {
        navigateToPickFavorites(0);
        performFavoritesSelection(0, noButtonId);
        performFavoritesSelection(0, maybeButtonId);
        performFavoritesSelection(0, yesButtonId);

        performFavoritesSelection(1, noButtonId);
        performFavoritesSelection(1, maybeButtonId);
        performFavoritesSelection(1, yesButtonId);
    }

What is the expected output? What do you see instead?

Expected: The test will cycle through all the button selections.
Actual: The results are inconsistent. Sometimes a button will not be selected. 
(e.g. on the device, it will appear as though "performFavoritesSelection(1, 
maybeButtonId);" is not called at times. The results are inconsistent. 
Sometimes, all6 calls are made. There are also times when 5/6 of the above 
calls are made.

What version of the product are you using? On what operating system?

Tested on a Nexus 4 on 4.4.2 and a Galaxy Tab 3 8.0 on 4.2.2

Please provide any additional information below.

None.

Original issue reported on code.google.com by kevingar...@gmail.com on 24 Jun 2014 at 10:49

GoogleCodeExporter commented 9 years ago

Original comment by nkors...@google.com on 5 May 2015 at 6:01

GoogleCodeExporter commented 9 years ago
The onData API is designed to be used against the underlying data of the 
adapter view. Using anything() and atPosition() will probably be flaky, 
depending on the implementation.

See the DataAdapterSample:

https://github.com/googlesamples/android-testing/blob/master/espresso/DataAdapte
rSample/app/src/androidTest/java/com/example/android/testing/espresso/DataAdapte
rSample/LongListActivityTest.java

Original comment by jalc@google.com on 6 May 2015 at 10:39