Issue
I'm not sure that it is correct implement "for loop" in tests with Espresso. I want to test first child of all parents in ExpandableListView. The potential code:
for(i = 0; i < length; i++){
onData(anything())
.inAdapterView(withId(R.id.userProfileActivityList))
.atPosition(i)
.check(matches(isDisplayed()))
.perform(click())
.check(matches(hasDescendant(isDisplayed())));
}
Thanks a lot.
Solution
Of course, why not? There are two thoughts I have on this.
A: What you've done is fine, good style, results in less code re-use etc.
B: I sometimes prefer code verbosity in test cases, for the sake of clarity of results. When my test cases fail, I want to know exactly why they failed, so I can quickly go back to my code and fix them. This is also the motivation of the "one assert per method" concept.
Think this: When this test case fails is it going to fail in a way that guides the developer to the proper functionality with clarity and ease?
If the answer to this question is yes, what else matters? Granted, this encompasses a lot! Maintaining generically good coding style in your test cases, good assertions with solid messages, and ensuring your asserts are placed to provide solid stack traces... just to name a few!
Answered By - ChrisCM
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.