Issue
I have a ProgressBar
which fills in as my user progresses through a sequence of actions.
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:indeterminate="false"
android:max="100"
android:progress="50"
... />
I would like write a test with JUnit and Espresso which asserts the value of the progress
attributes at different steps. Something like this...
onView(withId(R.id.progressBar)).check(matches(withProgress(50)));
Nothing similar to the withProgress
method seems to exist. What would be a way to assert the progress?
Solution
It would seem Espresso does not allow to check
the progress attribute using a ViewInteraction
. Although, it is possible to recover the progress bar view directly from the view and to assert its value using assertThat
.
@Test
public void ExampleAssertProgressBar(){
ProgressBar progressBar = activity.getActivity().findViewById(R.id.progressBar);
int progress = progressBar.getProgress();
assertThat(progress, equalTo(50));
}
Since this is pretty straightforward, I assume it is the way to go.
Answered By - Olivier Melançon
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.