Testing your React Native App is not important
Something you hear quite often, but is it true? In software engineering and app development, testing is an integral part. Some teams do it, some only the bare minimum, others nothing. Fact is, if you do not test your app, you expose it to crashes, bad user experience and development will slow down over time.
Regressions are issues, that appear even though the software should have been improved. So by adding a feature, the app got worse. Testing can make sure to prevent that problem. By having an automatic test execution (let’s say via CI/CD), you can ensure a certain quality of the product. Also, refactoring (changes in code that does not affect its functionality) can be supported by having tests in place.
In general, testing never shows the absence of bugs, only their presence. This is due to the fact, that it is pretty much impossible, to test a software in all its conditions. Also consider that people and environment influence this even more. You may call this side effects of a system.
The Agile Testing Pyramid shows a rough explanation of how testing may be applied in an agile (and traditional) working environment. Its main focus is on having many unit tests, to get fast feedback if something is broken. That can also be called rapid feedback cycle. This is due to the fact that the higher you go in the pyramid, the more costly, complicated, slow and unstable tests get.
Unit tests cover a single unit, isolated from other parts of your software. Integration tests include two or more units together, so that they are integrated. Testing the software as a whole, from the user’s perspective, given a specific flow or scenario, is called end-to-end test.
A React Native app can be tested in all these layers, too. For unit- and integration tests, the simplest (which is often the best solution) is Jest. There is no other test library necessary, but alternatives like Cucumber.js or Mocha can be an option, if you want to do more advanced testing like writing tests natural language.
React components and Hooks can easily be tested with the react-native-testing-library. This also covers snapshot tests, that help with regression tests for components. The rendered output of a component is saved as text in your project, to check whether it changes in the future.
End-to-end tests are often a difficult topic, since they are thought to be difficult to implement, cost time to develop and maintain, as well as their flakiness. A test should not fail once in a while, when it usually runs successfully. Detox and Appium are both famous frameworks to handle E2E tests. They use a simulator to click through your app and evaluate actions, so you can make test assumptions.
My guide “ is now available on Gumroad. In includes 74 pages of content and the full source code of an example React Native app, completely tested with the testing-library, Appium and Detox. Use the code “reime005-medium-free” to get a free version — I would just ask you for a review, that would be great.