728x90
반응형
728x90
반응형
# Situation 신규 프로젝트 생성 후 필요한 Gradle Dependency 추가 Application 구동 테스트 시 에러 ## Error Log Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. 간단하게 직역하면, Database 연결을 위한 URL이 없다. implementation 'org.springframework.boot:spring-boot-starter-data-jpa' 즉, jpa dependency 추가 시 자동으로 Database 설정을 진행하는데 이때 연결을 위한 Database URL이 없다는 의미이다. Consider..
# Mockito @ExtendWith(MockitoExtension.class) Mockito의 Mock 객체를 사용하기 위해 선언 JUnit4는 RunWith(MockitoJUnitRunner.class) 사용 @InjectMocks 생성한 Mock 객체를 주입 sut : system under test @Mock Mock 객체를 생성 FLOW given - when - then given : 테스트 대상의 초기 상태 when : 어떤 상황이 되었을 때 then : 기대하는 상태 given 게시글 ID를 선언하고, 해당 ID로 조회하면 해당 게시글을 리턴 받는다. 일반적으로 Mockito의 when()을 given에 사용한다. 그래서 사용하는 것이 BDDMockito의 given()이다. when s..
@WebMvcTest Controller Layer Slice Test Application Context를 완전하게 구동하지 않고 Web Layer Test 진행 시 사용 즉, Present Layer 관련 Component만 Scan @SpringBootTest는 모든 Bean을 Load하기에 테스트 구동 시간이 길고, 무겁다 # Example @WebMvcTest(ArticleController.class) 명시한 Controller 지정 스캔 가능 MockMvc Test용 MVC 환경을 만들어 요청, 전송, 응답 기능을 제공하는 Utility Class 생성자 주입 사용, 이때 test package에서는 @Autiwired 생략이 불가능 Flow Controller를 거쳐 View가 호출 되는지..
# Spring-Data-Rest spring-data-rest는 domain model과 repository를 분석해서, RESTful API를 제공해준다. https://docs.spring.io/spring-data/rest/docs/current/reference/html/#getting-started.basic-settings Spring Data REST Reference Guide Spring Data REST presents a default view of the domain model you export. However, sometimes, you may need to alter the view of that model for various reasons. This section cove..
# Dependency # Yaml # data.sql 테스트용 DB Mock 데이터 Insert resources > data.sql 파일 생성 후 insert 쿼리 추가 Mock 데이터는 mockaroo 등 외부 사이트에서 쉽게 생성 가능 https://www.mockaroo.com/ Mockaroo - Random Data Generator and API Mocking Tool | JSON / CSV / SQL / Excel Mock your back-end API and start coding your UI today. It's hard to put together a meaningful UI prototype without making real requests to an API. By mak..
# Config @EnableJpaAuditing Audit 기능 활성화를 위한 어노테이션 AuditorAware createdBy, modifiedBy 맵핑을 위해 Bean 등록 # Auditing Field Entity 공통 요소를 추출하여 소스 중복 제거 createdAt createdBy modifiedAt modifiedBy @EntityListeners(AuditingEntityListener.class) Entity가 DB로 load/persist 되기 전후에 커스텀 로직을 선언하는 인터페이스 AuditingEntityListener 특정 어노테이션을 탐색하여 Entity 변경 시 해당 값들을 자동으로 업데이트 @CreatedDate @CreatedBy @LastModifiedDate @La..