Reputation: 79
I am working with Espresso in android at the moment, and I have this test, which is clicking a button, populating my listView and then logging the execution time of the action.
@RunWith(AndroidJUnit4::class)
class Test {
@get:Rule
val mActivityActivityTestRule = ActivityTestRule(MainActivity::class.java)
@Test
@Throws(java.lang.Exception::class)
fun test_fetchData_populates_listView() {
//Click the get_rec_articles button.
onView(withId(R.id.get_rec_articles_btn)).perform(click())
val start = System.currentTimeMillis()
//check if the listView is created.
onView(withId(R.id.rec_articles_listview)).check(matches(isDisplayed()))
//check if items can be clicked.
onData(CoreMatchers.anything()).inAdapterView(withId(R.id.rec_articles_listview)).atPosition(0).perform(click())
val end = System.currentTimeMillis()
val loadTime = (end - start)
Log.d("###### LOADTIME FOR FETCHDATA FUNCTION:", "" + loadTime + " MILLISECS ######")
}
}
I would like to find a good way to call the test 50 times and then get the average load time. I could just run it manually 50 times and then calculate it, but I have several tests which I would like the average load times from.
I have read the question on the site about the same topic and tried the suggested solutions, but it didn't help.
Upvotes: 0
Views: 1107
Reputation: 1678
I had a very similar issue and as a result I've created a library to run Android UI tests multiple times. Might be useful in your case: https://github.com/stepstone-tech/AndroidTestXRunner
As far as the load time goes, after running tests there's a JUnit report created with times of each test being placed in a generated JUNit report XML. You could get those values and calculate an average based on that.
Upvotes: 1