TDD (Test-driven Development) λ ν
μ€νΈ μ£Όλ κ°λ°λ‘μ ν
μ€νΈκ° μ£Όκ° λμ΄ κ°λ°νλ λ°©λ²λ‘ μ΄λ€.
TDDλ₯Ό μ¬μ©ν¨μΌλ‘μ¨ μ°λ¦¬λ
build.gradle
μ λ€μμ μΆκ°νλ€.
dependencies {
implementation 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
}
/web/dto
ν΄λλ₯Ό λ§λ λ€.HelloResponseDto.java
λ₯Ό λ§λ λ€.package com.example.demo.web.dto;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@Getter
@RequiredArgsConstructor
public class CryptoResponseDto {
private final String name;
private final int amount;
}
@Getter
@RequiredArgsConstructor
test
μλμ λμΌ κ΅¬μ‘°μ ν΄λλ₯Ό λ§λ λ€. web/dto
HelloResponseDtoTest.java
λ₯Ό λ§λ λ€.package com.example.demo.web.dto;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class HelloResponseDtoTest {
@Test
public void testForLombok() {
String name = "test";
int amount = 1000;
HelloResponseDto dto = new HelloResponseDto(name, amount);
assertThat(dto.getName()).isEqualTo(name);
assertThat(dto.getAmount()).isEqualTo(amount);
}
}
new HelloResponseDto(name, amount);
@assertThat
isEqualTo()
μ κ°μ΄ μ¬μ©ν μ μμJUnit
μ§μ λ©μλμ assertj
λ μ€ νλλ₯Ό μ ν μ¬μ© Test μ€ν
Run Test
λ₯Ό λλ₯΄λ©΄ unit testλ₯Ό μ§νν μ μλ€.
κ²°κ³Ό νμΈ
λλ²ν¬ μ½μ
μ μ무κ²λ νμλμ§ μλλ€.
Controller ν
μ€νΈμλ λ€λ₯΄κ² wasλ₯Ό νμλ‘νμ§ μκΈ° λλ¬Έμ΄λ€.
νμ§λ§ Test κ²°κ³Όλ VSCode μ’μΈ‘ νλΌμ€ν¬ μμ΄μ½μ ν΄λ¦νμ¬ νμΈν μ μλ€.
HelloResponseDto
ν΄λμ€μλ getter, constructorκ° μ μΈλμ§ μμμμλ μ½λλ μ μμ μΌλ‘ μλλλ€.# λΉλ
./gradlew build
# Spring-boot μ€ν
java -jar ./build/lib/*.jar
curl localhost:8080/hello # hello
λͺ¨λ μμ€λ κΉνλΈμ μ¬λ €λμλ€.
μ°Έκ³ μμ : μ€νλ§λΆνΈμ AWSλ‘ νΌμ ꡬννλ μΉ μλΉμ€