2025/02 42

@JsonTest를 사용한 JSON 직렬화 테스트

@JsonTest 스프링 애플리케이션 콘텍스트를 로드하고 사용 중인 특정 라이브러리에 대한 JSON 매퍼를 자동으로 구성(기본설정: 잭슨) JSON 슬라이스에 대한 통합 테스트package com.polarbookshop.catalogservice.web;import com.polarbookshop.catalogservice.domain.Book;import org.junit.jupiter.api.Test;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.test.autoconfigure.json.JsonTest;import org.springframework.boot.test.json...

@WebMvcTest를 사용한 REST 컨트롤러 테스트

@WebMvcTest:스프링 MVC 컨트롤러가 의도한 대로 작동하는지 테스트 가능(실제 서버 환경이 아닌) 모의 웹 환경에서 스프링 애플리케이션 콘텍스트를 로드하고 스프링 MVC 인프라를 설정하며 @RestController 및 @RestControllerAdvice와 같은 MVC 계층에서 사용되는 빈만 포함  웹 MVC 슬라이스에 대한 통합 테스트🔹 웹 MVC 슬라이스(Web MVC Slice)란?Spring Boot의 @WebMvcTest를 사용하면 웹 계층(Web Layer)만 테스트할 수 있는 "슬라이스 테스트"를 수행할 수 있습니다. 📌 "슬라이스(Slice)"란?전체 애플리케이션을 테스트하지 않고 특정 계층만 테스트하는 방식@WebMvcTest를 사용하면 Spring MVC(Web) 계층만..

@SpringBootTest 를 통한 통합 테스트

@SpringBootTest: 테스트를 실행할 때 테스트 클래스에서 애플리케이션 콘텍스트를 자동으로 부트스트랩하기 위해 사용. 스프링 리액티브 웹을 위해 테스트 의존성 추가(build.gradle)plugins { id 'java' id 'org.springframework.boot' version '3.4.1' id 'io.spring.dependency-management' version '1.1.7'}group = 'com.polarbookshop'version = '0.0.1-SNAPSHOT'java { toolchain { languageVersion = JavaLanguageVersion.of(17) }}repositories { mavenCentral()}dependencies { impl..

[Java] 26. Remove Duplicates from Sorted Array

난이도: EASY문제더보기Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same. Then return the number of unique elements in nums. Consider the number of unique elements of nums to be k, to get accepted, you need to do the following things: Change the array nums s..

[SQL50] 1148. Article Views I

난이도: EASY 문제더보기Table: Views +---------------+---------+ | Column Name   | Type    | +---------------+---------+ | article_id    | int     | | author_id     | int     | | viewer_id     | int     | | view_date     | date    | +---------------+---------+ There is no primary key (column with unique values) for this table, the table may have duplicate rows. Each row of this table indicates that some ..

[SQL50] 1683. Invalid Tweets

난이도: EASY 문제더보기Table: Tweets+----------------+---------+ | Column Name    | Type    | +----------------+---------+ | tweet_id       | int     | | content        | varchar | +----------------+---------+ tweet_id is the primary key (column with unique values) for this table. content consists of characters on an American Keyboard, and no other special characters. This table contains all the tweets ..

JUnit5를 이용한 단위 테스트

소스 작성중 JUnit 이 임포트가 안되는 문제가 생김.그래들엔 분명 spring-boot-starter-test 의존성이 있고, 책에선 이게 JUnit5, 모키토, 어서트J 같은 테스트 라이브러리를 프로젝트로 임포트 한다고 써있는데...! package com.polarbookshop.catalogservice.domain;import jakarta.validation.Validation;import jakarta.validation.Validator;import jakarta.validation.ValidatorFactory;import org.junit.jupiter.api.BeforeAll;//Book 객체의 유효성 검사 제약조건을 검증하기 위한 단위 테스트public class BookValid..

[Java] 21. Merge Two Sorted Lists

난이도: EASY문제더보기You are given the heads of two sorted linked lists list1 and list2. Merge the two lists into one sorted list. The list should be made by splicing together the nodes of the first two lists. Return the head of the merged linked list. Example 1: Input: list1 = [1,2,4], list2 = [1,3,4] Output: [1,1,2,3,4,4]Example 2: Input: list1 = [], list2 = [] Output: [] Example 3: Input: list1 = []..

[SQL50] 595. Big Countries

난이도: EASY 문제더보기Table: World +-------------+---------+ | Column Name | Type    | +-------------+---------+ | name        | varchar | | continent   | varchar | | area        | int     | | population  | int     | | gdp         | bigint  | +-------------+---------+ name is the primary key (column with unique values) for this table. Each row of this table gives information about the name of a country..

[SQL50] 584. Find Customer Referee

난이도: EASY 문제더보기Table: Customer+-------------+--------------+ | Column Name | Type | +-------------+--------------+ | id                | int          | | name         | varchar   | | referee_id  | int           | +-------------+--------------+ In SQL, id is the primary key column for this table. Each row of this table indicates the id of a customer, their name, and the id of the customer who ref..