[TIL] test code using jest & supertest modules
04/28/23
![[TIL] test code using jest & supertest modules](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1683555586668%2F23af059e-bfb8-4c54-aaea-3410a2d04534.png&w=3840&q=75)
Reasons why testing is important
It increases product stability.
It helps reduce side effects caused by adding or modifying features.
It enables coding without uncertainty.
It ultimately boosts productivity.
It makes debugging easier.
It helps avoid repetitive tasks during development.
It enables writing cleaner and more reusable code.
Types of Testing
Unit Testing - testing small-scale functionality, such as individual classes or methods.
Integration Testing - testing potential issues that could arise when combining multiple functionalities (including external libraries, database access, and the entire codebase).
Acceptance Testing - testing scenarios that align with user stories (from a business perspective).

E2E (End-to-end) Test: A test that verifies whether all the components necessary for the desired outcome in a given feature are working correctly together (from a technical perspective).

Testing in Layered Architecture:
Mock Functions: Used to mock specific methods in order to verify information such as whether a method has been called or if input values match without actually executing code that is time-consuming, expensive, or has dependencies.
DI (Dependency Injection): Refers to passing dependencies from one object to another that wants to use them. It allows for mocking using mock functions.
Constructor Injection: One way to implement DI. When calling an object's constructor, dependencies are passed in and the object uses those dependencies to execute code.
Unit Test
jest: Testing in each layer
Repository layer test
Service layer test
Controller layer test
Integration Test
- Supertest + jest: All API Request & Response test
![[코테] 그리디 문제 - 무지의 먹방 라이브](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1712215455263%2F1ac1f35a-8862-4e42-8d0c-e2bea01e04c0.png&w=3840&q=75)
![[코테] Bfs 토마토](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1709032619170%2F70056896-c857-444b-9c99-45bfcb466806.png&w=3840&q=75)
![[코테] Dfs 문제 유형 - 그래프 내에서 구분하여 카운트 하기](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1709019361383%2Fb0585d72-c808-4169-83a9-2724f312e927.png&w=3840&q=75)
![[코테] DFS vs BFS](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1708971211123%2F71f9386c-6a62-43b2-a602-4d084c24d6cf.png&w=3840&q=75)
![[코테] 여행경로](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1708971251412%2F27ce72ed-8ee7-4d13-a02f-ff4bbe50c4be.png&w=3840&q=75)