Question 1. What are the types of testing, and why are they used?
Unit Test
- Tests the smallest unit of code (function, component).
- Fast, easy to debug.
- Example: Verify that a React component renders correctly with given props.
Integration Test
- Ensures multiple modules work correctly together.
- Example: “Login form → API call → state update → UI reflects change.”
E2E Test (End-to-End)
- Simulates real user flows across the entire app.
- Uses tools like Cypress, Playwright, Selenium.
- Example: User can register → login → create a post successfully.
👉 Tests provide confidence, catch regressions, and improve reliability.
Question 2. What is React Testing Library (RTL)?
- A testing library focused on testing apps the way users interact with them.
- Avoids testing implementation details.
How it Works
render() renders the component in a virtual DOM.