Instrumentation Test or UI Testing in Android App

Instrumentation Test in Android 

Testing means check the features we develop works. Example: Clicking a button in screen and verify if the expected image appears. 

UI testing means testing the components on screen that the user can interact with. 

Android studio provides a powerful tool called Espresso to help developers efficiently do UI tests. 

Espresso is a testing framework that includes a set of APIs that simulates and schedules user interactions to help us as developers test an app's user interface. Rather than a developer poke around poke around an app to find out what works and what doesn't Espresso provides us the tools to automate the process. 

Most of the app we use have a lot of UI components. Ex. app which allows us to order icecream of various flavors. So all the touch pointes that user touch to order the icecream must be verified to make sure that the user's experience is seemless and funcitonal as anticipated. So rather than having a dedicated person touching hundreds of all those buttons for potentially hundreds of icecream flavors combinations. So espresso allows us to automate the manual process so they can be tested at scale and much more efficiently. 

Analysis of UI testing 

Steps to Manually UI Test. 

  1. Open the app and find the order button 
  2. Click the button 
  3. Check that the order summary activity opens. 
We can generalise this steps to any UI testing situations. 
  1. Find the View we are interested in. 
  2. Perform the Action on the view. 
  3. Check if the view does what you expected. 
We translate this steps into codes. 

On View 
  1. onView(ViewMatcher)
  2. perform(ViewAction)
  3. check(ViewAssertion)
On Data 
  1. onData(ObjectMatcher)
  2. DataOptions
  3. perform(ViewAction)
  4. check(ViewAssertion)

ViewMatcher : a class that helps us specify the View we're interested in the current View This matcher comes form Hamcrest matcher library. Which is a compilation of possible ways to help us identify a view matches what we're expecting using human readable language. 
So in our case, we can use the withID method to find the button on the screen. 

we use Click() method in ViewAction 

Assertion : a check to see if what we expected matches what actually happened. 
ViewAssertion : a class with methods that help use perform assertions, or checks, on Views. 


This process is meant to mimic a human testing the UI and be straightforward to use. 

Read my Espresso Tutorial post to know more about doing Instrumentation testing. 







Comments

Popular Posts