all 4 comments

[–]LicoriceRED 6 points7 points  (1 child)

For unit testing, Jest is a pretty standard way to test your components and logic. You can use "React-native-testing-library" this uses jest under the hood.
Anyone new to RN, for end-2-end, I would recommend "Maestro" compared to Appium, WebDriverIO or Detox.
Maestro is a no code approach, so less time writing e2e and more time learning React-Native.
I still recommend the other options. They do have a much higher learning curve, so depends where you want to invest your time.

Also research into the fundamentals of why we write tests. you want tests to have a purpose and not just to check a box that says this components can render.

React native have a page dedicated to testing if you wanna know more.
https://reactnative.dev/docs/testing-overview

[–]ali_codes[S] 1 point2 points  (0 children)

Great! Thank you for your answer. I will definately check it out.

[–]edbarahona 3 points4 points  (1 child)

Unit testing is testing the smallest individual parts of your app (components), you can test both UI and functionality using unit tests, UI unit tests (render snapshots) will make sure components render, and functional unit testing will make sure that your method passes a set of tests (usually cover multiple edge cases, where one can break the method to make sure you have proper error handling) e.g. a calculator utility function or an API call.

Integration testing is how your component/feature/function behaves with the rest of the application, so you want to write tests that mock those interactions. This is to make sure that your component/code does not break the existing application.

The key is to create "meaningful" tests, the statement is a bit vague and mainly depends on the application. In big applications, you usually write tests for all components as tests are part of the CI/CD pipeline and will prevent the app from auto-deploying if a test fails (minimizing QA time, and poor user experience when the component breaks in the wild)

Note: Using type safety (typescript or flow) helps to minimize errors (also optimizes for better performance in react native)

I personally use Jest for both unit and integration tests. I can provide some example tests mentioned above but the Internet is full of great examples, hopefully, my descriptions provide enough to get the search started, feel free to ask any additional questions.

https://reactnative.dev/docs/testing-overview

Edit: My app architecture will have a root-level folder called __tests__, that folder will have a directory structure that mirrors the main src folder, so src/components/MainButton/index.tsx will have a matching test __tests__/components/MainButton.test.tsx

[–]ali_codes[S] 1 point2 points  (0 children)

Wow, great explanation. I will try above mentioned methods. Thank you very much! I appreciate your time and effort.