๐Ÿคท[Spring Boot] 02 ํ…Œ์ŠคํŠธ ์ฝ”๋“œ

dsunniยท2020๋…„ 6์›” 18์ผ
0

spring-boot

๋ชฉ๋ก ๋ณด๊ธฐ
2/2

ใ€Œ์Šคํ”„๋ง ๋ถ€ํŠธ์™€ AW๋กœ ํ˜ผ์ž ๊ตฌํ˜„ํ•˜๋Š” ์›น ์„œ๋น„์Šคใ€๋ฅผ ๋ณด๊ณ  ๊ณต๋ถ€ํ•œ ๊ธฐ๋ก์ž…๋‹ˆ๋‹ค. (์šฐ๋‹นํƒ•ํƒ•)

๐Ÿ™Œ๐Ÿป๋ชฉํ‘œ

ํ…Œ์ŠคํŠธ ์ฝ”๋“œ์— ๋Œ€ํ•œ ๊ฐœ๋…
๋งŒ๋‚˜๋Š” ๋ชจ๋“  ์—๋Ÿฌ ์ฒ˜๋ฆฌํ•˜๊ธฐ

ํ…Œ์ŠคํŠธ ์ฝ”๋“œ

Why Test-Driven Development (TDD) | Marsner Technologies

TDD

TDD๋ž€ ํ…Œ์ŠคํŠธ๊ฐ€ ์ฃผ๋„ํ•˜๋Š” ๊ฐœ๋ฐœ์„ ๋œปํ•œ๋‹ค. ์ฆ‰ ํ…Œ์ŠคํŠธ์ฝ”๋“œ๋ฅผ ๋จผ์ € ์ž‘์„ฑํ•˜๋Š” ๊ฒƒ๋ถ€ํ„ฐ ๊ฐœ๋ฐœ์„ ์‹œ์ž‘ํ•œ๋‹ค.

  1. Red : ํ•ญ์ƒ ์‹คํŒจํ•˜๋Š” ํ…Œ์ŠคํŠธ๋ฅผ ๋จผ์ € ์ž‘์„ฑ
  2. Green : ํ…Œ์ŠคํŠธ๊ฐ€ ํ†ต๊ณผํ•˜๋Š” ํ”„๋กœ๋•์…˜ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑ
  3. Refactor : ํ…Œ์ŠคํŠธ๊ฐ€ ํ†ต๊ณผํ•˜๋ฉด ํ”„๋กœ๋•์…˜ ์ฝ”๋“œ๋ฅผ ๋ฆฌํŒฉํ† ๋งํ•จ

๋‹จ์œ„ ํ…Œ์ŠคํŠธ (Unit Test)

๋‹จ์œ„ ํ…Œ์ŠคํŠธ๋Š” TDD์˜ ์ฒซ ๋ฒˆ์งธ ๋‹จ๊ณ„์ธ ๊ธฐ๋Šฅ ๋‹จ์œ„์˜ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ž‘์„ฑ์„ ์˜๋ฏธํ•œ๋‹ค. TDD์™€ ๋‹ฌ๋ฆฌ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋ฅผ ๋จผ์ € ์ž‘์„ฑํ•  ํ•„์š”๋„, ๋ฆฌํŒฉํ† ๋ง์„ ํ•  ํ•„์š”๋„ ์—†๋‹ค.

์žฅ์ 

  • ์ž๋™ ๊ฒ€์ฆ์œผ๋กœ ์ธํ•œ ๋น ๋ฅธ ํ”ผ๋“œ๋ฐฑ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.
    • ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•ด ํ†ฐ์บฃ์„ ๊ณ„์† ์žฌ์‹œ์ž‘ ํ•˜๊ฑฐ๋‚˜ System.out.println()์„ ์‚ฌ์šฉํ•ด ๊ฐ’์„ ์ฐ์–ด๋ณด์ง€ ์•Š์•„๋„ ๋œ๋‹ค.
  • ๊ฐœ๋ฐœ์ž๊ฐ€ ๋งŒ๋“  ๊ธฐ๋Šฅ์„ ์•ˆ์ „ํ•˜๊ฒŒ ๋ณดํ˜ธํ•ด์ค€๋‹ค.
    • ์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•  ๋•Œ ๊ธฐ์กด์˜ ๊ธฐ๋Šฅ์ด ์—๋Ÿฌ๊ฐ€ ๋‚  ์ƒํ™ฉ์„ ๋Œ€๋น„ํ•  ์ˆ˜ ์žˆ๋‹ค.
  • ๊ฐœ๋ฐœ๋‹จ๊ณ„ ์ดˆ๊ธฐ์— ๋ฌธ์ œ๋ฅผ ๋ฐœ๊ฒฌํ•˜๊ฒŒ ๋„์™€์ค€๋‹ค.

ํ”„๋ ˆ์ž„์›Œํฌ

ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ž‘์„ฑ์„ ๋„์™€์ฃผ๋Š” ํ”„๋ ˆ์ž„์›Œํฌ์—๋Š” xUnit๊ฐ€ ์žˆ๋‹ค.

  • xUnit : ๊ฐœ๋ฐœํ™˜๊ฒฝ(x)์— ๋”ฐ๋ผ Unit ํ…Œ์ŠคํŠธ๋ฅผ ๋„์™€์ฃผ๋Š” ๋„๊ตฌ
    • Java - JUnit
    • DB - DBUnit
    • C++ - CppUniit
    • .net - NUnit

๐Ÿ”” groupId ์ฐพ๊ธฐ

groupId๋Š” build.gradle ํŒŒ์ผ ์•ˆ์— group๋กœ ๋ช…์‹œ๋˜์–ด์žˆใ„ธ ใ… ^^ na noon babo..

1. Junit4๋กœ ํ…Œ์ŠคํŠธ์ฝ”๋“œ ์ž‘์„ฑํ•˜๊ธฐ

(1) ํŒจํ‚ค์ง€ ์ƒ์„ฑ

  • java - package ์ƒ์„ฑ
    • ๋ณดํ†ต ํŒจํ‚ค์ง€๋ช…์€ ์›น ์‚ฌ์ดํŠธ ์ฃผ์†Œ์˜ ์—ญ์ˆœ์œผ๋กœ ํ•œ๋‹ค.
    • ์ง€๊ธˆ์€ groupId๋ฅผ ์ด์šฉํ•ด์„œ ์ƒ์„ฑ
      • com.studying.book.springboot

(2) ๋ฉ”์ธ ํด๋ž˜์Šค ์ƒ์„ฑ (Application.class)

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
  • @SpringBootApplication
    • ์Šคํ”„๋ง ๋ถ€ํŠธ์˜ ์ž๋™ ์„ค์ •, Bean ์ฝ๊ธฐ/์ƒ์„ฑ ์ž๋™ ์„ค์ •
    • ์ด ์–ด๋…ธํ…Œ์ด์…˜์ด ์žˆ๋Š” ์œ„์น˜๋กœ๋ถ€ํ„ฐ ์„ค์ •์„ ์ฝ๊ธฐ ๋•Œ๋ฌธ์— ํ•ญ์ƒ ํ”„๋กœ์ ํŠธ์˜ ์ตœ์ƒ๋‹จ์— ์œ„์น˜ํ•ด์•ผํ•จ
  • springApplication.run()
    • ๋‚ด์žฅ WAS์ธ ํ†ฐ์บฃ์„ ์‹คํ–‰
    • jarํŒŒ์ผ(์‹คํ–‰ ๊ฐ€๋Šฅํ•œ java ํŒจํ‚ค์ง• ํŒŒ์ผ)๋กœ ์‹คํ–‰

์™œ ๋‚ด์žฅ WAS๋ฅผ ์‚ฌ์šฉํ• ๊นŒ?

  • ์–ธ์ œ๋‚˜ ๊ฐ™์€ ํ™˜๊ฒฝ์—์„œ ์Šคํ”„๋ง ๋ถ€ํŠธ๋ฅผ ๋ฐฐํฌํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

(3) ํ…Œ์ŠคํŠธ Controller ์ƒ์„ฑ

@RestController
public class HelloController {

    @GetMapping("/hello")
    public String Hello() {
        return "hello!!";
    }
}
  • @RestController

    • JSON์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ์ปจํŠธ๋กค๋Ÿฌ๋กœ ์„ค์ •ํ•จ
    • ์˜ˆ์ „์—๋Š” @ResponseBody๋ฅผ ๊ฐ ๋ฉ”์†Œ๋“œ๋งˆ๋‹ค ์„ค์ •ํ–ˆ๋Š”๋ฐ ์ด์ œ๋Š” ํ•œ๋ฒˆ์— ๊ฐ€๋Šฅ!
  • @GetMapping

    • HTTP GET ์š”์ฒญ์„ ๋ฐ›์„ ์ˆ˜ ์žˆ๋Š” API๋ฅผ ๋งŒ๋“ค์–ด์คŒ

(4) ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ž‘์„ฑ

  • src/test/java ๋””๋ ‰ํ† ๋ฆฌ์— main์—์„œ ์ƒ์„ฑํ–ˆ๋˜ ํŒจํ‚ค์ง€๋ฅผ ์ƒ์„ฑ
  • HelloControllerTest.java ์ƒ์„ฑ
@RunWith(SpringRunner.class)
@WebMvcTest(controllers = HelloController.class)
public class HelloControllerTest {
    @Autowired
    private MockMvc mvc;

    @Test
    public void hello๊ฐ€_๋ฆฌํ„ด๋œ๋‹ค() throws Exception {
        String hello = "hello";

        mvc.perform(get("/hello"))
                .andExpect(status().isOk())
                .andExpect(content().string(hello));
    }
}
  • @RunWith(SpringRunner.class)

    • ์Šคํ”„๋ง ๋ถ€ํŠธ ํ…Œ์ŠคํŠธ์™€ JUnit ์‚ฌ์ด์˜ ์—ฐ๊ฒฐ์ž ์—ญํ• 
    • ํ…Œ์ŠคํŠธ ์ง„ํ–‰ํ•  ๋•Œ JUnit ๋‚ด์žฅ๋œ ์‹คํ–‰์ž ์™ธ SpringRunner์ด๋ผ๋Š” ์Šคํ”„๋ง ์‹คํ–‰์ž ์‚ฌ์šฉ
  • @WebMvcTest

    • Web(Srping MVC)์—๋งŒ ์ง‘์ค‘ํ•  ์ˆ˜ ์žˆ๋Š” ์–ด๋…ธํ…Œ์ด์…˜
    • ์„ ์–ธ์‹œ @Controller @ControllerAdvice ์‚ฌ์šฉ ๊ฐ€๋Šฅ
    • @Servce @Component @Repository๋Š” ์‚ฌ์šฉ ๋ถˆ๊ฐ€๋Šฅ
  • @Autowired

    • Java Bean ์ž๋™ ์ฃผ์ž…
  • private MockMvc mvc

    • ์›น API ํ…Œ์ŠคํŠธ์‹œ ์‚ฌ์šฉ
    • ์Šคํ”„๋ง MVC ํ…Œ์ŠคํŠธ์˜ ์‹œ์ž‘์ 
    • HTTP GET, POST์— ๋Œ€ํ•œ API ํ…Œ์ŠคํŠธ ๊ฐ€๋Šฅ
  • mvc.perform(get("/hello"))

    • MockMvc๋ฅผ ํ†ตํ•ด /hello ์ฃผ์†Œ๋กœ HTTP GET ์š”์ฒญ์„ ๋ณด๋ƒ„
    • ์ฒด์ด๋‹์ด ์ง€์›๋˜์–ด ๊ฒ€์ฆ ๊ธฐ๋Šฅ์„ ์ด์–ด์„œ ์ˆ˜ํ–‰ ๊ฐ€๋Šฅ
  • .andExpect(status().isOk())

    • mvc.perform์˜ ๊ฒฐ๊ณผ ๊ฒ€์ฆ
    • HTTP Header์˜ Status ๊ฒ€์ฆ
    • 200์ด๋ฉด OK!
  • .andExpect(content().string(hello));

    • mvc.perform์˜ ๊ฒฐ๊ณผ ๊ฒ€์ฆ
    • Response ๋ณธ๋ฌธ์˜ ๋‚ด์šฉ ๊ฒ€์ฆ
    • Controller์˜ ๋ฆฌํ„ด ๊ฐ’์ด hello์ด๋ฉด OK!

(5) ์ˆ˜๋™ ์‹คํ–‰

  • Application.java ํŒŒ์ผ main ๋ฉ”์†Œ๋“œ ์™ผ์ชฝ์˜ ํ™”์‚ดํ‘œ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ด ์‹คํ–‰ํ•ด๋ณด๊ธฐ

๐Ÿ””ERROR!

๋‹ค๋“ค ์•„์‹œ๋Š” ๊ทธ ์—๋Ÿฌ์ž…๋‹ˆ๋‹ค. (8080 ํฌํŠธ ๋ฒˆํ˜ธ๊ฐ€ ์ด๋ฏธ ์‚ฌ์šฉ์ค‘)


IntelliJ Spring Boot(Gradle) ํฌํŠธ ๋ฒˆํ˜ธ ๋ณ€๊ฒฝํ•˜๋Š” ๋ฒ•

  1. Run - Edit Configurations
  2. Environment variables ์ถ”๊ฐ€
    • Name : server.port
    • value : 5858(์›ํ•˜๋Š” ํฌํŠธ๋ฒˆํ˜ธ)


2. ๋กฌ๋ณต (Lombok) ์ถ”๊ฐ€ํ•˜๊ธฐ

๋กฌ๋ณต ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ์ž๋ฐ” ๊ฐœ๋ฐœํ•  ๋•Œ ์ž์ฃผ ์‚ฌ์šฉํ•˜๋Š” ์ฝ”๋“œ์ธ Getter, Setter, ๊ธฐ๋ณธ ์ƒ์„ฑ์ž, toString ๋“ฑ์„ ์–ด๋…ธํ…Œ์ด์…˜์œผ๋กœ ์ž๋™ ์ƒ์„ฑํ•ด์ค€๋‹ค.

๋กฌ๋ณต ํ”Œ๋Ÿฌ๊ทธ์ธ ์„ค์น˜๋Š” ํ•œ ๋ฒˆ๋งŒ ํ•ด๋„ ๋˜์ง€๋งŒ

๋กฌ๋ณต ์„ค์ •์€ ํ”„๋กœ์ ํŠธ๋งˆ๋‹ค ํ•ด์ค˜์•ผํ•œ๋‹ค. (build.gradle ์ถ”๊ฐ€)


(1) build.gradle์— ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ถ”๊ฐ€

compile('org.projectlombok:lombok')
  • build.gradle์— ๋“ฑ๋ก์„ ํ•ด์„œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๋‹ค์šด๋ฐ›์Œ

(2) Lombok ํ”Œ๋Ÿฌ๊ทธ์ธ ์„ค์น˜

  • ctrl+shift+A - plugins
  • lombok ๋‹ค์šด
  • Enable annotation processing ์ฒดํฌ


3. ๊ธฐ์กด ์ฝ”๋“œ ๋กฌ๋ณต์œผ๋กœ ์ „ํ™˜

(1) HelloResponseDto.java

package com.studying.book.springboot.web.dto;

@Getter
@RequiredArgsConstructor
public class HelloResponseDto {
    private final String name;
    private final int amount;
}
  • @Getter
    • ์„ ์–ธ๋œ ๋ชจ๋“  ํ•„๋“œ์˜ get ๋ฉ”์†Œ๋“œ ์ƒ์„ฑ
  • @RequiredArgsConstructor
    • ์„ ์–ธ๋œ ๋ชจ๋“  final ํ•„๋“œ๊ฐ€ ํฌํ•จ๋œ ์ƒ์„ฑ์ž๋ฅผ ๋งŒ๋“ค์–ด์คŒ
    • final ์—†์œผ๋ฉด ํฌํ•จ X

(2) HelloResponseDtoTest.java

package com.studying.book.springboot.web.dto;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;

public class HelloResponseDtoTest {
    @Test
    public void ๋กฌ๋ณต_๊ธฐ๋Šฅ_ํ…Œ์ŠคํŠธ() {
        //given
        String name="test";
        int amount = 1000;

        //when
        HelloResponseDto dto = new HelloResponseDto(name, amount);

        //then
        assertThat(dto.getName()).isEqualTo(name);
        assertThat(dto.getAmount()).isEqualTo(amount);
    }
}
  • assertThat
    • assertj๋ผ๋Š” ํ…Œ์ŠคํŠธ ๊ฒ€์ฆ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ๊ฒ€์ฆ ๋ฉ”์†Œ๋“œ
    • ๊ฒ€์ฆํ•˜๊ณ  ์‹ถ์€ ๋Œ€์‚ฌ๋ฅผ ์ธ์ž๋กœ ๋ฐ›์•„ ๋ฉ”์†Œ๋“œ ์ฒด์ด๋‹ ์ง€์›๋˜์–ด isEqualTo๊ฐ™์€ ๋ฉ”์†Œ๋“œ ์‚ฌ์šฉ ๊ฐ€๋Šฅ
  • isEqualTo
    • assertj์˜ ๋น„๊ต ๋ฉ”์†Œ๋“œ
    • ๊ฐ’์ด ๊ฐ™์„ ๋•Œ๋งŒ ์„ฑ๊ณต
  • ํ…Œ์ŠคํŠธ ์„ฑ๊ณต์„ ํ†ตํ•ด Getter์™€ ์ƒ์„ฑ์ž๊ฐ€ ๋กฌ๋ณต์„ ํ†ตํ•ด ์ƒ์„ฑ๋˜์—ˆ์Œ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

๐Ÿ””Cannot resolve symbol 'assertThat' ERROR!

์ถœ์ฒ˜ : https://aonee.tistory.com/2

  • ์›์ธ : junit4์˜ ๊ฒฝ์šฐ org.junit.Assert ํด๋ž˜์Šค์—์„œ ํ—ˆ์šฉํ•˜๋Š” Hamcrest ํ—ˆ์šฉ ๋ฉ”์†Œ๋“œ๋ฅผ ์ œ๊ณตํ•˜์ง€ ์•Š์•˜๊ธฐ ๋•Œ๋ฌธ

  • ํ•ด๊ฒฐ : gradle ์˜์กด์„ฑ ์ถ”๊ฐ€

    1. build.gradle

      dependencies {
      	testCompile 'junit:junit:4.12'
      }
  1. ์ƒˆ๋กœ ์ถ”๊ฐ€๋œ Gradle์„ ์ ์šฉํ•˜๊ธฐ ์œ„ํ•ด Gradle-Reimport All Gradle Project (์ƒˆ๋กœ๊ณ ์นจ ์ด๋ชจํ‹ฐ์ฝ˜)์„ ํด๋ฆญ!

    • ์ƒˆ๋กœ ์ถ”๊ฐ€๋œ gradle import ๊ฐ€๋Šฅ
  2. More actions ... - import static method - 3๋ฒˆ์งธ์˜ Assertions.assertThat ํด๋ฆญ!

    • import static org.assertj.core.api.Assertions.assertThat;
  3. ์™„๋ฃŒ! ์จ–์จ–์จ–


๐Ÿ”” ํ…Œ์ŠคํŠธ ์‹คํŒจ ์—๋Ÿฌ! ๋กฌ๋ณต ์—๋Ÿฌ!

๋Š” ์ด ๋ชจ๋“  ์—๋Ÿฌ๊ฐ€.. Gradle ๋ฒ„์ „ ๋•Œ๋ฌธ์ด์—ˆ๋‹ค.๐Ÿ’ฉ

error: variable name not initialized in the default constructor private final String name;

์ž์ž˜ํ•œ ์—๋Ÿฌ๋“ค๊ณผ ํ•จ๊ป˜ ์œ„์™€ ๊ฐ™์€ ์—๋Ÿฌ๋“ค์ด ์ž๊พธ ๋– ์„œ ๊ตฌ๊ธ€๋งํ•œ ๊ฒฐ๊ณผ ์ €์ž๋‹˜์˜ ์ด์Šˆ์—์„œ ํ•ด๊ฒฐ๋ฐฉ๋ฒ•์„ ์ฐพ์•˜๋‹ค.

์ฑ…์˜ ์˜ˆ์ œ๋“ค์€ Gradle 4 ๊ธฐ์ค€์œผ๋กœ ์“ฐ์—ฌ์ ธ์žˆ๋Š” ์ƒํƒœ์ด๊ณ ! ๋กฌ๋ณต์ด Gradle 5๋กœ ๋˜๋ฉด์„œ ๋งŽ์ด ๋ณ€๊ฒฝ๋˜์—ˆ๋‹ค๊ณ ํ•œ๋‹ค!

  • ์›์ธ : Gradle ๋ฒ„์ „ ๋ฌธ์ œ
  • ํ•ด๊ฒฐ๋ฐฉ๋ฒ• : Gradle 4๋กœ Downgradeํ•˜๊ธฐ

Gradle ๋ฒ„์ „ ๋‹ค์šด๊ทธ๋ ˆ์ด๋“œ

  1. alt+F12 ์œผ๋กœ ํ„ฐ๋ฏธ๋„ ์—ด๊ธฐ
  2. ./gradlew wrapper --gradle-version 4.10.2 ์ž…๋ ฅ
  3. gradle - wrapper - gradle-wrapper.properties์—์„œ ๋ฒ„์ „ ํ™•์ธ!

์ถ”๊ฐ€๋กœ ํ™˜๊ฒฝ ์„ค์ • ํ•˜๋‚˜ํ•˜๋‚˜ ํ•˜๊ธฐ ๊ท€์ฐฎ์œผ๋‹ˆ...

java-resources ํด๋” ์•ˆ์— new - file - application.properties ์ƒ์„ฑํ•ด์„œ

server.port=5858

ํฌํŠธ๋ฒˆํ˜ธ๋ฅผ ์ง€์ •ํ•ด์คฌ๋‹ค. ใ…ก ๋ ใ…ก๐Ÿคข



(3) HelloController.java

@RestController
public class HelloController {
    @GetMapping("/hello")
    public String Hello() {
        return "hello";
    }

    @GetMapping("/hello/dto")
    public HelloResponseDto helloDto(@RequestParam("name") String name,
                                     @RequestParam("amount") int amount) {
        
        return new HelloResponseDto(name, amount);
    }
}
  • @RequestParam
    • ์™ธ๋ถ€์—์„œ API๋กœ ๋„˜๊ธด ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ์–ด๋…ธํ…Œ์ด์…˜
    • ์™ธ๋ถ€์—์„œ name์œผ๋กœ ๋„˜๊ธด ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ String name์— ์ €์žฅ

(4) HelloControllerTest.java

@RunWith(SpringRunner.class)
@WebMvcTest(HelloController.class)
public class HelloControllerTest {
    @Autowired
    private MockMvc mvc;

    @Test
    public void hello๊ฐ€_๋ฆฌํ„ด๋œ๋‹ค() throws Exception {
        String hello = "hello";

        mvc.perform(get("/hello"))
                .andExpect(status().isOk())
                .andExpect(content().string(hello));
    }

    @Test
    public void helloDto๊ฐ€_๋ฆฌํ„ด๋œ๋‹ค() throws Exception {
        String name = "hello";
        int amount = 1000;

        mvc.perform(get("/hello/dto")
                .param("name", name)
                .param("amount", String.valueOf(amount)))
                    .andExpect(status().isOk())
                    .andExpect(jsonPath("$.name", is(name)))
                    .andExpect(jsonPath("$.amount", is(amount)));
    }
}
  • param
    • API ํ…Œ์ŠคํŠธ์‹œ ์š”์ฒญ ํŒŒ๋ผ๋ฏธํ„ฐ ์„ค์ •
    • ๊ฐ’์€ String๋งŒ ํ—ˆ์šฉ๋จ!
      • ์ˆซ์ž/๋‚ ์งœ ๋“ฑ์€ ๋ฌธ์ž์—ด๋กœ ๋ณ€๊ฒฝํ•ด์„œ ์‚ฌ์šฉ
        • String.valueOf(amount)
  • jsonPath
    • JSON ์‘๋‹ต๊ฐ’์„ ํ•„ใ„ท๋ณ„๋กœ ๊ฒ€์ฆํ•  ์ˆ˜ ์žˆ๋Š” ๋ฉ”์†Œ๋“œ
    • $๋ฅผ ๊ธฐ์ค€์œผ๋กœ ํ•„๋“œ๋ช…์„ ๋ช…์‹œ
    • $.name $.amount

๐Ÿ”” ํ…Œ์ŠคํŠธ status() ์—์„œ 404 ์—๋Ÿฌ๊ฐ€ ๋œฌ๋‹ค?

  • ์˜ˆ.. 404 ์—๋Ÿฌ๊ฐ€ ๋œฌ๋‹ค๋ฉด ๋ฌด.์กฐ.๊ฑด URI๋ฅผ ํ•œ๋ฒˆ ๋” ํ™•์ธํ•ฉ์‹œ๋‹ค.
  • ์ € ๊ฐ™์€ ๊ฒฝ์šฐ์—๋Š” get ("/hello/dto")๊ฐ€ ์•„๋‹Œ ("hello/dto")๋กœ ๋งคํ•‘์‹œ์ผœ์„œ 404 ์—๋Ÿฌ๊ฐ€ ๋‚˜์™”์Šต๋‹ˆ๋‹ค....๐Ÿ’ฉ

๐Ÿ”” non-ascii characters in an identifier intellij

  • ์ปค๋ฐ‹ํ•  ๋•Œ "Non-ascii " ์–ด์ฉŒ๊ตฌ ์—๋Ÿฌ์‹œ
  • ctrl+shift+a + settings - inspections- non-ascii character - ์ฒดํฌ๋ฐ•์Šค ํ•ด์ œ

profile
https://dsunni.tistory.com/ ์ด์‚ฌ๊ฐ‘๋‹ˆ๋‹ต

0๊ฐœ์˜ ๋Œ“๊ธ€