App Configuration

Testing Dotenv 터미널에서 npm install @nestjs/config dotenv 는 .env 파일과 일반적인 환경 변수파일을 참조하여 개체를 생성(겹칠시 환경변수 파일 우선)한다. .env 파일은 배포에 포함되선 안된다. (git 에선 gitignore로 commit되지 않도록 해야) 우리는 개발용(배포용) .env 파일과 테스트용 .env 파일 두 개를 만들것이다. root 디렉토리에 .env.tset 와 .env.development 파일 두개를 만들자. 1 2 // .env.development DB_NAME=db.sqlite 1 2 // .env.test DB_NAME=test.sqlite AppModule에 아래와 같이 설정해준다. ...

2023년 10월 10일 · 4 분 · 배준수

end to end testing

Testing End to End test 유닛 테스트보다 넓은 범위를 테스트 전체 서비스의 복사본이나 인스턴스 생성 package.json 의 script를 보면 "test:e2e"가 있음. src 폴더 내의 파일 실행 X 서버를 끄고 터미널에서 npm run test:e2e를 입력해보자. 새로운 E2E 테스트 만들기 test 폴더에 auth.e2e-spec.ts 파일을 만들고 app.e2e-spec.ts의 내용을 복사 붙여넣자. 이 후 조금의 수정을 가한다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 // auth.e2e-spec.ts import { Test, TestingModule } from '@nestjs/testing'; import { INestApplication } from '@nestjs/common'; import * as request from 'supertest'; import { AppModule } from './../src/app.module'; describe('Authentication System', () => { let app: INestApplication; beforeEach(async () => { const moduleFixture: TestingModule = await Test.createTestingModule({ imports: [AppModule], }).compile(); app = moduleFixture.createNestApplication(); await app.init(); }); it('handles a signup request', () => { // 알아보기 쉬운 주석 return request(app.getHttpServer()) .post('/auth/signup') // signup 경로 .send({ email: 'asgkege@akl.com', password: 'qownstn' }) // 무작위 body .expect(201) .then((res) => { // response id, email로 올 것 const { id, email } = res.body; expect(id).toBeDefined(); expect(email).toEqual(email); }); }); }); 터미널에서 npm run test:e2e를 실행하면 문제가 발생한다. 이유를 알아보자. ...

2023년 10월 10일 · 3 분 · 배준수

냄새와 휴리스틱(5)

책너두 5기 44일차 로버트 C. 마틴의 클린코드 p. 404~ p.412 내용정리 17. 냄새와 휴리스틱 테스트 1. 불충분한 테스트 테스트 케이스는 잠재적으로 깨질만한 부분을 모두 테스트해야 한다. 확인하지 않는 조건이나 검증하지 않는 계산이 있다면 그 테스트는 불완전하다. 2. 커버리지 도구를 사용하라 커버리지 도구는 테스트가 빠뜨리는 공백을 시각적으로 알려준다. 3. 사소한 테스트를 건너뛰지 마라 사소한 테스트는 짜기 쉽고 제공하는 문서적 가치는 구현에 드는 비용을 넘어선다. 4. 무시한 테스트는 모호함을 뜻한다 불분명한 요구사항은 테스트 케이스를 주석으로 처리하거나 테스트 케이스에 @ignore를 붙여 표현한다. ...

2023년 9월 26일 · 2 분 · 배준수