Testing As your codebase expands, small errors and edge cases you don’t expect can cascade into larger failures. One way to prevent fragile programming is to test your code before releasing it into the wild. Here are different automated ways to ensure your app works as expected, ranging from static analysis to end-to-end tests.

Why Test

Humans make mistakes, and testing helps uncover them

Writing Tests

The default template of React Native ships with Jest testing framework

Unit tests

These cover the smallest parts of code, like individual functions or classes.

Testing User Interactions

Aside from rendering some UI, your components handle events like onChangeText for TextInput or onPress for Button.

Static Analysis

Check your code for errors as you write it, without running any of it

Testing Rendered Output

With snapshot testing, you typically first implement your component and then run the snapshot test.

Writing Testable Code

To start with tests, you first need to write code that is testable.

Component Tests

React components are responsible for rendering your app, and users will directly interact with their output

End-to-End Tests

Verifies that your app is working as expected on a device from the user perspective

Summary

There are many ways to test your app

Structuring Tests

Short and ideally test only one thing

Mocking

Replace some dependency of your code with your own implementation

Integration Tests

When writing larger software systems, individual pieces of it need to interact with each other

Source

Get in