Since I started building apps I was sure of only two things: one is that I love seeing users enjoying my apps; and the second is that I hate seeing users clicking everywhere and crashing them. So how can I be sure that my users will be able to have a joyful experience (even with those features that are hidden 15 clicks away and that I don’t even remember they exist anymore)? By testing them all!
What is UI testing and why to automate it?
UI testing is nothing more than simulating the user’s environment, performing the available actions and verifying if everything is behaving correctly.
Of course anyone can test features by simply having a human doing this job, but how time-consuming, boring and error-prone can it be? By having automated UI tests we assure that all the features will be tested reliably and quickly. We also become more confident to create or refactor features by being sure that if something gets broken we will know what and where the problem is, leading to faster development, less bugs, and better design decisions.
If it’s not clear yet, by using UI automated tests a specific user’s action or input can be simulated and we can check if it returns the correct UI behavior. Besides that, interactions between our app and a third-one can also be tested to be sure that features like content-sharing are working perfectly. All of it can be achieved by using testing frameworks like Espresso or UI Automator.
Do not get fooled by your data!
It’s also important to use a framework to mock the data while testing the app, like Mockito, for example, since by relying on real APIs during testing we cannot control the scenario, exposing tests to failures in the external APIs. It’s also good to mention that by relying on external APIs we are essentially writing integration tests, which is not our objective here.
Another important point to think about is to choose a test-friendly architecture (aka modular ones) that will allow us to change from mock data during tests to real data during production.
When to stop testing?
A particular point of testing is that it’s endless and it’s very important to decide when and where to stop it, mostly because software has a huge testing scope and, even though it’s possible to cover all the problematic points it can have, it will take like forever. So, it’s needed to get into a point where we can say that the existent tests are enough to prove that the app does work as intended, serving to its proposal.
Conclusion
To wrap it up, keep in mind that automating UI testing is a great way to ensure that actions available in the app will have the expected behavior, which can lead to better user experience, also a more free and enjoyable programming time.
TL;DR
By automating UI testing we simulate the user actions and assure that everything is how we expect. Use testing frameworks to make it easier, like Espresso or UI Automator as well as Mockito to mock your data and not get fooled by unpredictable external APIs content. Embrace the reliability that it can offer and be more confident to do changes in your code. Enjoy!