I recently wrote a blog, Clear the Clutter with Fragments, with that my co-worker Anne had a clever idea to find ways to Marie Kondo your code! For those not familiar with this concept, it’s about removing what does not spark joy in your life. From KonMari.com:
Our goal is to help more people live a life that sparks joy, and we are committed to offering the simplest, most effective tools and services to help you get there.
Obviously we can’t remove all things in our code that does not bring us joy, but what about putting things in, that do bring joy? This might be a controversial statement but automated tests do bring me joy, and confidence in my code.
As developers, we all hear about automated testing, and yet it seems to rarely be a priority. From my experience, it’s often undervalued by the business owners and thus takes a back seat to continuing to deliver new features, and thus one of the first things to be removed from the planning board.
But what happens when we keep delivering new features only to find we have a regression on something else within the application? This could be a super basic feature like logging in, or perhaps something more complex like navigating three levels deep with certain elements expected to be visible. Either way, some simple End to End (E2E) Integration tests could help relieve that worry.
With React Native you have a few options for E2E testing, however most common is the use of Detox. This third party library integrates with your project for both iOS and Android, and thus allows you to write one set of tests for both platforms. After following a short setup guide you are on your way to testing visibility, taps, scrolls, and whatever interaction you would like.
On a recent project, where we have no control of the backend API, we were suddenly unable to login to the application during development. This brought the perfect opportunity to share with their team, the value of automated tests. I made a screen recording of the application and shared with them how this will be running, and automated through Continuous Integration as we check-in feature branches. This provides confidence in Continuous Delivery and helps to ensure we are not regressing as we continue to develop or iterate on features.
In this video, you can see with a simple command it builds, loads, and validates some basic functionality. Ensuring a username and password field exist. If I input incorrect values I get an error message, as expected, and if I submit correct credentials I navigate to the home screen. After this, we also then ensure on our main/home screen that a few key elements are visible. Our client was very impressed to see this and it will help continue the conversation with them as we estimate work moving forward, to include those tests.
We’ve all been there. Worrying about a code change having a bigger impact than we expect. It’s that time of year where we reflect on the past year, decisions we’ve made, accomplishments, and goals we want to achieve in the new year. Consider a focus on adding value-add E2E tests to your projects, and thus bring joy to your life with higher code confidence!