-
Notifications
You must be signed in to change notification settings - Fork 15
BE 코드 컨벤션
hongo edited this page Aug 17, 2023
·
1 revision
-
메서드 파라미터와 로컬 변수
-
클래스
-
값이 변하지 않는 필드
-
prod/test 모두 해당
public void findLineWithStationsById(final Long id) { final Line line = lines.findById(id); }
-
메서드 네이밍
- 테스트 할 메서드 이름
- 여러 개 라면 _ 로 구분 후 대문자로 시작하는 단어 붙이기
- 영어 사용
-
Annotation 순서
-
@DisplayName
,@Test
순서로 배치
-
-
given-when-then
주석-
when & then
으로 붙여서 사용 가능 - // 후 공백
- 주석 간 공백
- given 없는 경우 생략
-
-
여러 개의 assert문이 필요하면
assertSoftly()
사용@DisplayName("내가 테스트할 기능을 세부적으로 적는다.") @Test @Transactional void methodName_AddtionalInformation() { // given // when // then }
public final class Station() {
private final Long id;
private final String name;
private void getName() {
// method contents
}
}
-
메서드 세로 길이는 유동적으로 관리
- 20줄 이상시 분리 권고
-
매개변수 4개부터 세로로 작성 (아래와 같이)
public Station( final Long id, final String name, final String length, final String address ) { this.id = id; this.name = name; this.length = length; this.address = address; }
- 단, 매개변수 3개여도 가로 라인(120자)을 넘으면 아래와 같이 작성
final TripCreateRequest tripCreateRequest = new TripCreateRequest( LocalDate.of(2023, 7, 2), LocalDate.of(2023, 7, 7), List.of(1L, 2L) );
- 한 줄에 하나의 점 (stream, builder)
- ResponseEntity는 예외
members.stream()
.filter()
.map()
.toList();
// ResponseEntity는 예외
ResponseEntity.ok().body(memberCouponService.getMemberCoupons(member.getId()));