๋Œ€์™ธํ™œ๋™/์šฐํ…Œ์ฝ” ํ”„๋ฆฌ์ฝ”์Šค 6๊ธฐ

์šฐํ…Œ์ฝ” ํ”„๋ฆฌ์ฝ”์Šค 1์ฃผ์ฐจ ํ”ผ๋“œ๋ฐฑ ์ •๋ฆฌ(๊ฐœ๋ฐœ ์š”๊ตฌ์‚ฌํ•ญ ์ž‘์„ฑ, ๊ฐ์ฒด ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ, junit)

kite707 2023. 10. 31.

1์ฃผ์ฐจ ํ”ผ๋“œ๋ฐฑ ์ •๋ฆฌ

์ด ๊ธ€์€ ์šฐํ…Œ์ฝ” 1์ฐจ ๊ณผ์ œ ํ”ผ๋“œ๋ฐฑ์„ ํ†ตํ•ด ๋ฐฐ์šด ์ ์„ ๊ธฐ๋กํ•˜๋Š” ๊ธ€์ž…๋‹ˆ๋‹ค. ๊ฐ•์˜๋ฅผ ๋ณด๊ณ  ์ƒˆ๋กœ ์ž‘์„ฑํ•œ ์ฝ”๋“œ๋Š” ์•„๋ž˜ ๋งํฌ์—์„œ ๋ณด์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

https://github.com/kite707/java-baseball-6/tree/kite707_feedback

 

GitHub - kite707/java-baseball-6

Contribute to kite707/java-baseball-6 development by creating an account on GitHub.

github.com

๋จผ์ € ์ด๋ฒˆ 1์ฃผ์ฐจ์˜ ๊ณตํ†ต ํ”ผ๋“œ๋ฐฑ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์•˜์Šต๋‹ˆ๋‹ค.

  1. ์š”๊ตฌ ์‚ฌํ•ญ์„ ์ •ํ™•ํžˆ ์ค€์ˆ˜ํ•œ๋‹ค.
  2. ์ปค๋ฐ‹ ๋ฉ”์‹œ์ง€๋ฅผ ์˜๋ฏธ์žˆ๊ฒŒ ์ž‘์„ฑํ•œ๋‹ค.
  3. git์„ ํ†ตํ•ด ๊ด€๋ฆฌํ•  ์ž์›์— ๋Œ€ํ•ด์„œ๋„ ๊ณ ๋ คํ•œ๋‹ค.
  4. Pull Request๋ฅผ ๋ณด๋‚ด๊ธฐ ์ „ ๋ธŒ๋žœ์น˜๋ฅผ ํ™•์ธํ•œ๋‹ค.
  5. PR์„ ํ•œ ๋ฒˆ ์ž‘์„ฑํ–ˆ๋‹ค๋ฉด ๋‹ซ์ง€ ๋ง๊ณ  ์ถ”๊ฐ€ ์ปค๋ฐ‹์„ ํ•œ๋‹ค.
  6. ์ด๋ฆ„์„ ํ†ตํ•ด ์˜๋„๋ฅผ ๋“œ๋Ÿฌ๋‚ธ๋‹ค.
  7. ์ถ•์•ฝํ•˜์ง€ ์•Š๋Š”๋‹ค.
  8. ๊ณต๋ฐฑ๋„ ์ฝ”๋”ฉ ์ปจ๋ฒค์…˜์ด๋‹ค.
  9. ๊ณต๋ฐฑ ๋ผ์ธ์„ ์˜๋ฏธ ์žˆ๊ฒŒ ์‚ฌ์šฉํ•œ๋‹ค.
  10. space ์™€ tab์„ ํ˜ผ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค.
  11. ์˜๋ฏธ ์—†๋Š” ์ฃผ์„์„ ๋‹ฌ์ง€ ์•Š๋Š”๋‹ค.
  12. IDE์˜ ์ฝ”๋“œ ์ž๋™ ์ •๋ ฌ ๊ธฐ๋Šฅ์„ ํ™œ์šฉํ•œ๋‹ค.
    mac : โŒฅโŒ˜L
    window : Ctrl+Alt+L
  13. Java์—์„œ ์ œ๊ณตํ•˜๋Š” API๋ฅผ ์ ๊ทน ํ™œ์šฉํ•œ๋‹ค.
    ex)List<String> members = Arrays.asList("pobi", "jason");
         String result = String.join(",", members); // "pobi,jason"
  14. ๋ฐฐ์—ด ๋Œ€์‹  Java Collection์„ ์‚ฌ์šฉํ•œ๋‹ค. Map, Set, List ๋“ฑ

์ด ์ค‘์—์„œ ์ œ๊ฐ€ ์ฐธ๊ณ ํ• ๋งŒํ•œ ๋ถ€๋ถ„์€ ๊ตต๊ฒŒ ํ‘œ์‹œํ•˜์˜€์Šต๋‹ˆ๋‹ค.

 

์šฐํ…Œ์ฝ”์—์„œ๋Š” 1์ฃผ์ฐจ ๊ณผ์ œ์ธ “์ˆซ์ž ์•ผ๊ตฌ ๊ฒŒ์ž„”์— ๋Œ€ํ•ด ์˜์ƒ ํ”ผ๋“œ๋ฐฑ๋„ ์ œ๊ณตํ•˜์˜€์Šต๋‹ˆ๋‹ค. Java์— ๋Œ€ํ•œ ๊ธฐ์ดˆ์ ์ธ ๋‚ด์šฉ๋“ค๊ณผ “์ˆซ์ž ์•ผ๊ตฌ ๊ฒŒ์ž„” ๊ณผ์ œ๋ฅผ ์ˆ˜ํ–‰ํ•˜๋Š” ๋ชจ์Šต์„ ๋ผ์ด๋ธŒ ์ฝ”๋”ฉ์œผ๋กœ ๋ณด์—ฌ์ฃผ๋Š” ์˜์ƒ์ด์—ˆ์Šต๋‹ˆ๋‹ค.

 

๋ผ์ด๋ธŒ ์ฝ”๋”ฉ์„ ํ•˜๊ธฐ ์•ž์„œ ์ œ์ด์Šจ์€ ๊ฐ์ฒด ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์„ ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•„๋ž˜์™€ ๊ฐ™์ด ๋งํ–ˆ์Šต๋‹ˆ๋‹ค.

  1. ๊ธฐ๋Šฅ์„ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ํด๋ž˜์Šค๋ฅผ ์ธ์Šคํ„ด์Šคํ™” ํ•œ๋‹ค.
  2. ํ•„์š”ํ•œ ๊ธฐ๋Šฅ์„ ์ธ์Šคํ„ด์Šค๊ฐ€ ์ˆ˜ํ–‰ํ•˜๊ฒŒ ํ•œ๋‹ค.(์˜์ธํ™”)
  3. ๊ฐ ๊ฒฐ๊ณผ๋ฅผ ์ข…ํ•ฉํ•œ๋‹ค.

 

์ดํ›„ ๊ฐœ๋ฐœ ๋ฌธ์„œ๋ฅผ ์ž‘์„ฑํ•˜์˜€์Šต๋‹ˆ๋‹ค. ์šฐํ…Œ์ฝ”์—์„œ๋Š” ๊ฐœ๋ฐœ ์š”๊ตฌ์‚ฌํ•ญ์„ ๋ฌธ์„œ๋กœ ์ •๋ฆฌํ•œ ๋’ค ๊ฐœ๋ฐœ์„ ์‹œ์ž‘ํ•  ๊ฒƒ์„ ๊ถŒ์žฅํ•ฉ๋‹ˆ๋‹ค. ์ œ๊ฐ€ ์ด์ „์— ์ž‘์„ฑํ–ˆ๋˜ ๊ฐœ๋ฐœ ์š”๊ตฌ์‚ฌํ•ญ ๋ฌธ์„œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์•˜์Šต๋‹ˆ๋‹ค.

## ๊ธฐ๋Šฅ ๊ตฌํ˜„

- [x] 3์ž๋ฆฌ ์ž„์˜์˜ ์ •๋‹ต ์ƒ์„ฑ
- [x] ์‚ฌ์šฉ์ž์˜ ์ž…๋ ฅ์„ ๋ฐ›์•„ ๋ณผ, ์ŠคํŠธ๋ผ์ดํฌ ๋“ฑ์˜ ๊ฒฐ๊ณผ ์ถœ๋ ฅ
- [x] ๊ฒŒ์ž„ ์žฌ์‹œ์ž‘์—ฌ๋ถ€ ๊ฒฐ์ • ๊ธฐ๋Šฅ

## ์˜ˆ์™ธ ์ฒ˜๋ฆฌ

์ž…๋ ฅ๊ฐ’์ด ์กฐ๊ฑด์— ๋ถ€ํ•ฉํ•˜์ง€ ์•Š์„ ์‹œ IllegalArgumentException ๋ฐœ์ƒ

- [x] ์‚ฌ์šฉ์ž๊ฐ€ ์ˆซ์ž๊ฐ€ ์•„๋‹Œ ๊ฐ’์„ ์ž…๋ ฅํ–ˆ์„ ๋•Œ
- [x] ์‚ฌ์šฉ์ž๊ฐ€ 3์ž๋ฆฌ๊ฐ€ ์•„๋‹Œ ๊ฐ’์„ ์ž…๋ ฅํ–ˆ์„ ๋•Œ
- [x] ๊ฒŒ์ž„ ์žฌ์‹œ์ž‘ ์—ฌ๋ถ€๋ฅผ ๊ฒฐ์ •ํ•  ๋•Œ 1์ด๋‚˜ 2๊ฐ€ ์•„๋‹Œ ๋‹ค๋ฅธ ๊ฐ’์„ ์ž…๋ ฅํ–ˆ์„ ๋•Œ

๊ฐ•์˜์— ๋“ฑ์žฅํ•œ ๊ฐœ๋ฐœ ์š”๊ตฌ์‚ฌํ•ญ ๋ฌธ์„œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์•˜์Šต๋‹ˆ๋‹ค.

# ์ˆซ์ž ์•ผ๊ตฌ ๊ฒŒ์ž„

## ๊ธฐ๋Šฅ ๋ชฉ๋ก

- [x] 1-9๊นŒ์ง€์˜ ์„œ๋กœ ๋‹ค๋ฅธ ์ž„์˜์˜ ์ˆ˜ 3๊ฐœ๋ฅผ ์ƒ์„ฑํ•œ๋‹ค. NumberGenerator/createRandomNumbers()
- [x] ์ปดํ“จํ„ฐ์˜ ์ˆ˜์™€ ํ”Œ๋ ˆ์ด์–ด์˜ ์ˆ˜๋ฅผ ๋น„๊ตํ•œ๋‹ค. - Referee(์‹ฌํŒ)/compare()
    - [x] ๋ช‡ ๊ฐœ์˜ ์ˆซ์ž๊ฐ€ ๊ฐ™์€์ง€ ์•Œ ์ˆ˜ ์žˆ๋‹ค. - Judgement/correctCount()
    - [x] ํŠน์ • ์ž๋ฆฌ์— ํŠน์ • ์ˆซ์ž๊ฐ€ ์žˆ๋Š”์ง€ ์•Œ ์ˆ˜ ์žˆ๋‹ค. - Judgement/hasPlace()
- [x] ๊ฐ™์€ ์ˆ˜๊ฐ€ ๋‹ค๋ฅธ ์ž๋ฆฌ์— ์žˆ์œผ๋ฉด ๋ณผ์ด๋‹ค.
- [x] ๊ฐ™์€ ์ˆ˜๊ฐ€ ๊ฐ™์€ ์ž๋ฆฌ์— ์žˆ์œผ๋ฉด ์ŠคํŠธ๋ผ์ดํฌ์ด๋‹ค.
- [x] ๊ฐ™์€ ์ˆ˜๊ฐ€ ์ „ํ˜€ ์—†์œผ๋ฉด ๋‚ซ์‹ฑ์ด๋‹ค.

## ๊ธฐ๋Šฅ ์š”๊ตฌ ์‚ฌํ•ญ

๊ธฐ๋ณธ์ ์œผ๋กœ 1๋ถ€ํ„ฐ 9๊นŒ์ง€ ์„œ๋กœ ๋‹ค๋ฅธ ์ˆ˜๋กœ ์ด๋ฃจ์–ด์ง„ 3์ž๋ฆฌ์˜ ์ˆ˜๋ฅผ ๋งž์ถ”๋Š” ๊ฒŒ์ž„์ด๋‹ค.

๊ฐ™์€ ์ˆ˜๊ฐ€ ๊ฐ™์€ ์ž๋ฆฌ์— ์žˆ์œผ๋ฉด ์ŠคํŠธ๋ผ์ดํฌ, ๋‹ค๋ฅธ ์ž๋ฆฌ์— ์žˆ์œผ๋ฉด ๋ณผ, ๊ฐ™์€ ์ˆ˜๊ฐ€ ์ „ํ˜€ ์—†์œผ๋ฉด ๋‚ซ์‹ฑ์ด๋ž€ ํžŒํŠธ๋ฅผ ์–ป๊ณ , ๊ทธ ํžŒํŠธ๋ฅผ ์ด์šฉํ•ด์„œ ๋จผ์ € ์ƒ๋Œ€๋ฐฉ(์ปดํ“จํ„ฐ)์˜ ์ˆ˜๋ฅผ ๋งž์ถ”๋ฉด ์Šน๋ฆฌํ•œ๋‹ค.

e.g. ์ƒ๋Œ€๋ฐฉ(์ปดํ“จํ„ฐ)์˜ ์ˆ˜๊ฐ€ 425์ผ ๋•Œ
123์„ ์ œ์‹œํ•œ ๊ฒฝ์šฐ : 1์ŠคํŠธ๋ผ์ดํฌ
456์„ ์ œ์‹œํ•œ ๊ฒฝ์šฐ : 1๋ณผ 1์ŠคํŠธ๋ผ์ดํฌ
789๋ฅผ ์ œ์‹œํ•œ ๊ฒฝ์šฐ : ๋‚ซ์‹ฑ

๊ธฐ๋Šฅ ๋ชฉ๋ก์„ ์ž‘์„ฑํ•˜๋ฉฐ ์–ด๋–ค ํŒŒ์ผ์— ์–ด๋–ค ํ•จ์ˆ˜๋“ค์„ ๋ฐฐ์น˜ํ• ์ง€ ๊ณ„ํšํ•˜์—ฌ ํ•จ๊ป˜ ์ž‘์„ฑํ•œ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ €๋Š” ๊ฐ ๊ธฐ๋Šฅ์„ ๋ฉ”์„œ๋“œํ™”ํ•˜๊ธฐ๋Š” ํ–ˆ์ง€๋งŒ ๋ชจ๋“  ๊ธฐ๋Šฅ๋“ค์ด Application.javaํŒŒ์ผ์— ์กด์žฌํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ฐœ๋ฐœ ๋ฌธ์„œ๋ฅผ ์ž‘์„ฑํ•˜๋Š” ๋ถ€๋ถ„์„ ํ†ตํ•ด ๊ฐ ๊ธฐ๋Šฅ์„ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ํด๋ž˜์Šค๋ฅผ ์ธ์Šคํ„ด์Šคํ™” ํ•˜์—ฌ ํ•„์š”ํ•œ ๊ธฐ๋Šฅ์„ ์ธ์Šคํ„ด์Šค๊ฐ€ ์ˆ˜ํ–‰ํ•˜๊ฒŒ ํ•œ๋‹ค. ๋ผ๋Š” ๊ฒƒ์ด ์–ด๋–ค ๋ง์ธ์ง€ ๋Š๋‚„ ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

 

์ดํ›„ ์œ„์—์„œ ๋ณธ๋Œ€๋กœ NumberGenerator, Referee, Judgement ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด ๊ฐ๊ฐ createRandomNumbers(), compare()๋“ฑ์˜ ๋ฉ”์„œ๋“œ๋ฅผ ๊ตฌํ˜„ํ•ฉ๋‹ˆ๋‹ค.

 

์ฆ‰ ํ˜„์žฌ๊นŒ์ง€์˜ ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ๋Š” ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

์ดํ›„ ๊ฐ ๊ฒฐ๊ณผ๋ฅผ ์ข…ํ•ฉํ•˜์—ฌ Application.javaํŒŒ์ผ์„ ๊ตฌ์„ฑํ•ฉ๋‹ˆ๋‹ค. ์ฐธ๊ณ ๋ฅผ ์œ„ํ•ด Jason์ด ์ž‘์„ฑํ•œ ์ฝ”๋“œ์™€ ์ œ๊ฐ€ ์ž‘์„ฑํ•œ ์ฝ”๋“œ๋ฅผ ์ฒจ๋ถ€ํ•˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

//Jason์˜ ์ฝ”๋“œ
package baseball;

import baseball.domain.NumberGenerator;
import baseball.domain.Referee;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Application {
    public static void main(String[] args) {
        NumberGenerator generator = new NumberGenerator();
        List<Integer> computer = generator.createRandomNumbers();

        Referee referee = new Referee();

        String result = "";
        while (!result.equals("0 ๋ณผ 3 ์ŠคํŠธ๋ผ์ดํฌ")) {
            result = referee.compare(computer, askNumbers());
            System.out.println(result);
        }
        System.out.println("3๊ฐœ์˜ ์ˆซ์ž๋ฅผ ๋ชจ๋‘ ๋งžํžˆ์…จ์Šต๋‹ˆ๋‹ค! ๊ฒŒ์ž„ ์ข…๋ฃŒ");

    }

    public static List<Integer> askNumbers() {
        System.out.println("์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š” : ");
        Scanner scanner = new Scanner(System.in);
        String input = scanner.next();

        List<Integer> numbers = new ArrayList<>();
        for (String number : input.split("")) {
            numbers.add(Integer.valueOf(number));
        }
        return numbers;
    }
}
//์ œ์ถœ ์ฝ”๋“œ
package baseball;

import camp.nextstep.edu.missionutils.Console;
import camp.nextstep.edu.missionutils.Randoms;
import java.util.ArrayList;
import java.util.List;

public class Application {
    public static final int BALL = 1;
    public static final int STRIKE = 2;
    public static final int NOTHING = 3;
    public static final int RESTART = 1;
    public static final int LENGTH = 3;

    public static List<Integer> getAnswer() {
        List<Integer> answer = new ArrayList<>();
        while (answer.size() < LENGTH) {
            int randomNumber = Randoms.pickNumberInRange(1, 9);
            if (!answer.contains(randomNumber)) {
                answer.add(randomNumber);
            }
        }
        return answer;
    }

    public static Integer ballOrStrike(int idx, char userInput, List<Integer> answer) {
        int result = NOTHING;
        int curInput = userInput - '0';
        if (answer.contains(curInput)) {
            result = BALL;
        }
        if (answer.get(idx) == curInput) {
            result = STRIKE;
        }
        return result;
    }

    public static boolean evaluator(String userInput, List<Integer> answer) {
        int strike = 0;
        int ball = 0;

        for (int i = 0; i < userInput.length(); i++) {
            char curInput = userInput.charAt(i);
            int result = ballOrStrike(i, curInput, answer);
            if (result == BALL) {
                ball++;
            }
            if (result == STRIKE) {
                strike++;
            }
        }
        return replyToUser(strike, ball);
    }

    public static boolean replyToUser(int strike, int ball) {
        if (strike == 3) {
            System.out.println("3์ŠคํŠธ๋ผ์ดํฌ\n3๊ฐœ์˜ ์ˆซ์ž๋ฅผ ๋ชจ๋‘ ๋งžํžˆ์…จ์Šต๋‹ˆ๋‹ค! ๊ฒŒ์ž„ ์ข…๋ฃŒ");
            return false;
        }
        if (ball > 0) {
            System.out.print(ball + "๋ณผ ");
        }
        if (strike > 0) {
            System.out.print(strike + "์ŠคํŠธ๋ผ์ดํฌ ");
        }
        if (strike == 0 && ball == 0) {
            System.out.print("๋‚ซ์‹ฑ");
        }
        System.out.println();
        return true;
    }

    public static boolean isGameRestart(String userRestart) {
        if (userRestart.charAt(0) - '0' == RESTART) {
            return true;
        }
        return false;
    }

    public static void validateUserInput(String userInput) {
        if (userInput.length() != LENGTH) {
            throw new IllegalArgumentException();
        }
        for (int i = 0; i < userInput.length(); i++) {
            int curInput = userInput.charAt(i) - '0';
            if (curInput < 0 || curInput > 9) {
                throw new IllegalArgumentException();
            }
        }
    }

    public static void validateUserRestart(String userRestart) {
        if (userRestart.length() != 1) {
            throw new IllegalArgumentException();
        }
        int curInput = userRestart.charAt(0) - '0';
        if (curInput != 1 && curInput != 2) {
            throw new IllegalArgumentException();
        }
    }

    public static void main(String[] args) {
        System.out.println("์ˆซ์ž ์•ผ๊ตฌ ๊ฒŒ์ž„์„ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.");
        boolean isGameRestart = true;
        while (isGameRestart) {
            List<Integer> answer = getAnswer();
            boolean isIncorrect = true;
            while (isIncorrect) {
                System.out.print("์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š” : ");
                String userInput = Console.readLine();
                validateUserInput(userInput);
                isIncorrect = evaluator(userInput, answer);
            }
            System.out.println("๊ฒŒ์ž„์„ ์ƒˆ๋กœ ์‹œ์ž‘ํ•˜๋ ค๋ฉด 1, ์ข…๋ฃŒํ•˜๋ ค๋ฉด 2๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”.");
            String userRestart = Console.readLine();
            validateUserRestart(userRestart);
            isGameRestart = isGameRestart(userRestart);
        }

    }
}

์ œ ์ฝ”๋“œ์˜ ๊ฒฝ์šฐ mainํ•จ์ˆ˜์—์„œ ๋ชจ๋“  ๊ธฐ๋Šฅ์„ ์ˆ˜ํ–‰ํ•˜๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์ฝ”๋“œ๊ฐ€ ์ƒ๋‹นํžˆ ๊ธธ๊ณ , ๊ฐ์ฒด ์ง€ํ–ฅ์˜ ์›์น™์„ ๋”ฐ๋ฅด์ง€ ๋ชปํ•œ ๊ฒƒ์„ ๋ณด์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

์ดํ›„์—๋Š” ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋ฅผ ์งœ๋Š” ๊ฒƒ์„ ๋ณด์—ฌ์ฃผ์…จ๋Š”๋ฐ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ์˜ ๊ฒฝ์šฐ Referee class์— ๋Œ€ํ•˜์—ฌ ์ž‘์„ฑํ•˜์˜€์Šต๋‹ˆ๋‹ค. ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋ฅผ ๋ณด๊ธฐ ์•ž์„œ Referee์ฝ”๋“œ๋ฅผ ๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

 

์ปดํ“จํ„ฐ๊ฐ€ ์ƒ์„ฑํ•œ ์„ธ ์ž๋ฆฌ ์ˆ˜์™€ ํ”Œ๋ ˆ์ด์–ด๊ฐ€ ์ž…๋ ฅํ•œ ์„ธ ์ž๋ฆฌ ์ˆ˜๋ฅผ ๋น„๊ตํ•˜์—ฌ ๋ณผ, ์ŠคํŠธ๋ผ์ดํฌ๋ฅผ ๊ฐ๊ฐ ์ถœ๋ ฅํ•˜๋Š” ๊ธฐ๋Šฅ์„ ํ•˜๋Š” ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค.

package baseball.domain;

import java.util.List;

public class Referee {
    public String compare(List<Integer> computer, List<Integer> player) {
        final Judgement judgement = new Judgement();
        int correctCount = judgement.correctCount(computer, player);

        int strike = 0;
        for (int placeIndex = 0; placeIndex < player.size(); placeIndex++) {
            if (judgement.hasPlace(computer, placeIndex, player.get(placeIndex))) {
                strike++;
            }
        }
        int ball = correctCount - strike;
        if (correctCount == 0) {
            return "๋‚ซ์‹ฑ";
        }
        return ball + " ๋ณผ " + strike + " ์ŠคํŠธ๋ผ์ดํฌ";
    }
}

์ธํ…”๋ฆฌ์ œ์ด๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด ๋งฅ๋ถ์˜ ๊ฒฝ์šฐ ํ•ด๋‹น ํŒŒ์ผ์—์„œ โŒ˜+shift+T, ์œˆ๋„์šฐ๋Š” ctrl+shft+T๋ฅผ ๋ˆ„๋ฅด๋ฉด ์•„๋ž˜์™€ ๊ฐ™์€ ํŒŒ์ผ์ด ์ž๋™ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.

package baseball.domain;

import static org.junit.jupiter.api.Assertions.*;

class RefereeTest {

}

์ดํ›„ ์ŠคํŠธ๋ผ์ดํฌ, ๋ณผ์ด ์ž˜ ๋ฆฌํ„ด๋˜๋Š”์ง€ ์•„๋ž˜์™€ ๊ฐ™์ด compare()ํ•จ์ˆ˜์˜ ๊ธฐ๋Šฅ์„ ๊ฒ€์ฆํ•˜๋Š” ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜์˜€์Šต๋‹ˆ๋‹ค. ๊ฐ€๋…์„ฑ์„ ์œ„ํ•ด import๋ฌธ์€ ์ œ๊ฑฐํ•˜์˜€์Šต๋‹ˆ๋‹ค.

 

์—ฌ๊ธฐ์„œ ์ฃผ๋ชฉํ• ๋งŒํ•œ ์ ์€ ๊ฐ ํ…Œ์ŠคํŠธ์—์„œ ์ค‘๋ณต๋˜๋Š” ๋ถ€๋ถ„์„ ๋ฏธ๋ฆฌ private ๋ณ€์ˆ˜๋กœ ์„ ์–ธํ•ด์ฃผ์—ˆ๋‹ค๋Š” ์ , refereeํด๋ž˜์Šค์˜ ์ƒ์„ฑ์ž๋ฅผ ๊ฐ ํ…Œ์ŠคํŠธ๊ฐ€ ์ˆ˜ํ–‰๋˜๊ธฐ ์ „์— ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•ด @BeforeEach๋ฅผ ์‚ฌ์šฉํ–ˆ๋‹ค๋Š” ์ ์ž…๋‹ˆ๋‹ค.

class RefereeTest {
        **//์ค‘๋ณต๋˜๋Š” ๋ถ€๋ถ„ ๋ฏธ๋ฆฌ ๋ณ€์ˆ˜๋กœ ์„ ์–ธ
    private Referee referee;
    private static final List<Integer> ANSWER = Arrays.asList(1, 2, 3);

    @BeforeEach //๊ฐ ํ…Œ์ŠคํŠธ๊ฐ€ ์ˆ˜ํ–‰๋˜๊ธฐ ์ „ ์‹คํ–‰
    void setUp() {
        referee = new Referee();
    }**

    @Test
    void ์ŠคํŠธ๋ผ์ดํฌ3() {
        String result = referee.compare(ANSWER, Arrays.asList(1, 2, 3));
        assertThat(result).isEqualTo("0 ๋ณผ 3 ์ŠคํŠธ๋ผ์ดํฌ");
    }

    @Test
    void ๋‚ซ์‹ฑ() {
        String result = referee.compare(ANSWER, Arrays.asList(7, 8, 9));
        assertThat(result).isEqualTo("๋‚ซ์‹ฑ");
    }

    @Test
    void ๋ณผ3() {
        String result = referee.compare(ANSWER, Arrays.asList(2, 3, 1));
        assertThat(result).isEqualTo("3 ๋ณผ 0 ์ŠคํŠธ๋ผ์ดํฌ");
    }

    @Test
    void ๋ณผ2_์ŠคํŠธ๋ผ์ดํฌ1() {
        String result = referee.compare(ANSWER, Arrays.asList(1, 3, 2));
        assertThat(result).isEqualTo("2 ๋ณผ 1 ์ŠคํŠธ๋ผ์ดํฌ");
    }

}

๊ทธ๋Ÿฐ๋ฐ ์ด ๊ฒฝ์šฐ์—๋„ ์ฝ”๋“œ์— ์ค‘๋ณต๋˜๋Š” ๋ถ€๋ถ„์ด ์ƒ๋‹นํžˆ ๋งŽ์Šต๋‹ˆ๋‹ค. ์ด๋ฅผ ๊ฐœ์„ ํ•˜๊ธฐ ์œ„ํ•ด @ParameterizedTest์™€ @CsvSource๋ฅผ ์‚ฌ์šฉํ•˜์˜€์Šต๋‹ˆ๋‹ค. ์ฝ”๋“œ๊ฐ€ ํ›จ์”ฌ ๊ฐ„๊ฒฐํ•ด ์ง„ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

class RefereeTest {
    private Referee referee;
    private static final List<Integer> ANSWER = Arrays.asList(1, 2, 3);

    @BeforeEach
    void setUp() {
        referee = new Referee();
    }

    @ParameterizedTest
    @CsvSource({"1,2,3,0 ๋ณผ 3 ์ŠคํŠธ๋ผ์ดํฌ", "7,8,9,๋‚ซ์‹ฑ", "2,3,1,3 ๋ณผ 0 ์ŠคํŠธ๋ผ์ดํฌ", "1,3,2,2 ๋ณผ 1 ์ŠคํŠธ๋ผ์ดํฌ"})
    public void compare(int number1, int number2, int number3, String expected) {
        String actual = referee.compare(ANSWER, Arrays.asList(number1, number2, number3));
        assertThat(actual).isEqualTo(expected);
    }

์œ„ ์ฝ”๋“œ๋ฅผ ๋ณด๊ณ  ๊ฐ„๋‹จํ•˜๊ฒŒ ์„ค๋ช…ํ•˜์ž๋ฉด @CsvSource์˜ ์ธ์ž๋กœ ์ฃผ์–ด์ง€๋Š” ํฐ ๋”ฐ์˜ดํ‘œ์˜ ์‹œ์ž‘์ ๋ถ€ํ„ฐ ๋ ์ ์ด ํ•˜๋‚˜์˜ ํ…Œ์ŠคํŠธ๋ผ๊ณ  ์ƒ๊ฐํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค. ์ฆ‰ ์•„๋ž˜ ์ฝ”๋“œ์—์„œ๋Š” "1,2,3,0 ๋ณผ 3 ์ŠคํŠธ๋ผ์ดํฌ"๊ฐ€ ํ•˜๋‚˜์˜ ํ…Œ์ŠคํŠธ๊ฐ€ ๋˜๊ฒ ์ฃ ?

 

์ด ํ…Œ์ŠคํŠธ๋Š” ,(์ฝค๋งˆ) ๋‹จ์œ„๋กœ compare()ํ•จ์ˆ˜์˜ ์ธ์ž๋กœ ๋“ค์–ด๊ฐ€๊ฒŒ ๋˜๋Š”๋ฐ ์—ฌ๊ธฐ์„œ๋Š” ๊ฐ ์ธ์ž์˜ ๊ฐ’์ด ์•„๋ž˜์™€ ๊ฐ™์ด ๋ฉ๋‹ˆ๋‹ค.

๐Ÿ“š compare()ํ•จ์ˆ˜์˜ ์ธ์ž
number1 = 1
number2 = 2
number3= 3
expected = 0 ๋ณผ 3 ์ŠคํŠธ๋ผ์ดํฌ

@ParameterizedTest๋Š” ๋‹ค์–‘ํ•œ ์–ด๋…ธํ…Œ์ด์…˜๊ณผ ํ•จ๊ป˜ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. ์ฆ‰ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ์–ด๋–ค ๊ฐ’์ด ์ฃผ์–ด์งˆ์ง€๋ฅผ ์•Œ๋ ค์ฃผ๋Š” ์–ด๋…ธํ…Œ์ด์…˜๊ณผ ํ•จ๊ป˜ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋Š”๋ฐ์š”. @CsvSource์™ธ์˜ ๋‹ค๋ฅธ ์–ด๋…ธํ…Œ์ด์…˜์„ ์‚ดํŽด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

1. ValueSource

ValueSource๋Š” ๋‹ค์–‘ํ•œ ํƒ€์ž…์˜ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๋ฐฐ์—ด๋กœ ๋ฐ›์•„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ๋Š” ์–ด๋…ธํ…Œ์ด์…˜์ž…๋‹ˆ๋‹ค. ๊ฐ ํƒ€์ž…๋ช…์˜ ์†Œ๋ฌธ์ž์— s๋ฅผ ๋ถ™์—ฌ ํŒŒ๋ผ๋ฏธํ„ฐ์˜ ํƒ€์ž…์„ ์•Œ๋ ค์ค๋‹ˆ๋‹ค. ๋‹ค๋งŒ ํŒŒ๋ผ๋ฏธํ„ฐ ์ธ์ž๋Š” 1๊ฐœ๋งŒ ๋„ฃ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ฆ‰ ์•„๋ž˜์™€ ๊ฐ™์ด ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

@ParameterizedTest
    @ValueSource(ints = {1, 2, 3, -1})
    public void compare(int number1) {
        assertThat(number1 > 0).isEqualTo(true);
    }

number1์— 1, 2, 3, -1์ด ๋“ค์–ด๊ฐ”์„๋•Œ์˜ ํ…Œ์ŠคํŠธ ๊ฒฐ๊ณผ๋ฅผ ๊ฐ๊ฐ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

2. CsvSource

CSV(Comma Seperated Values)๋Š” ์ฝค๋งˆ๋ฅผ ๊ธฐ์ค€์œผ๋กœ CSV๋ฅผ ๊ตฌ๋ถ„ํ•˜์—ฌ ์ฝ์Šต๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ์˜ ๊ตฌ๋ถ„์ž ์ฝค๋งˆ๋Š” ๊ธฐ๋ณธ๊ฐ’์ด๋ฉฐ ์ปค์Šคํ„ฐ๋งˆ์ด์ง•์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ์•ž์„œ ๋ณธ ๊ฒƒ๊ณผ ๊ฐ™์ด ๊ฐ String๊ฐ’์„ ์ฝค๋งˆ๋กœ ๊ตฌ๋ถ„ํ•ด ๊ฐ ์ธ์ž์— ์ง‘์–ด๋„ฃ์Šต๋‹ˆ๋‹ค. ์ฆ‰ ์—ฌ๋Ÿฌ๊ฐœ์˜ ์ธ์ž๋ฅผ ๋ฐ›๋Š” ํ•จ์ˆ˜๋„ ํ…Œ์ŠคํŠธ๊ฐ€ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

@ParameterizedTest
    @CsvSource({"1,2,3,0 ๋ณผ 3 ์ŠคํŠธ๋ผ์ดํฌ", "7,8,9,๋‚ซ์‹ฑ", "2,3,1,3 ๋ณผ 0 ์ŠคํŠธ๋ผ์ดํฌ", "1,3,2,2 ๋ณผ 1 ์ŠคํŠธ๋ผ์ดํฌ"})
    public void compare(int number1, int number2, int number3, String expected) {
        String actual = referee.compare(ANSWER, Arrays.asList(number1, number2, number3));
        assertThat(actual).isEqualTo(expected);
    }

3. MethodSource

๋ณต์žกํ•œ ์ธ์ˆ˜๋“ค์„ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๋„˜๊ธฐ๋Š” ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค. Stream์„ ๋ฐ˜ํ™˜ํ•˜๋Š” static ๋ฉ”์„œ๋“œ๋ฅผ ์ž‘์„ฑํ•ด์ฃผ๋ฉด ๋˜๋Š”๋ฐ ์‚ฌ์šฉ ์˜ˆ์‹œ๋ฅผ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

๋จผ์ € ์•„๋ž˜์™€ ๊ฐ™์ด Integer๋ฆฌ์ŠคํŠธ๋ฅผ ๋ฐ›์•„ ๋ฆฌ์ŠคํŠธ ์† ๊ฐ’๋“ค์„ ํ•ฉ์ณ์ฃผ๋Š” ํ•จ์ˆ˜๊ฐ€ ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

public class MathUtils {
    public static int sum(List<Integer> numbers) {
        return numbers.stream().mapToInt(Integer::intValue).sum();
    }
}

๊ทธ๋ฆฌ๊ณ  ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.

class MathUtilsTest {

        //stream์„ ๋ฐ˜ํ™˜ํ•˜๋Š” static ๋ฉ”์„œ๋“œ
    static Stream<List<Integer>> provideNumberLists() {
        return Stream.of(
                Arrays.asList(1, 2, 3, 4, 5),
                Arrays.asList(10, 20, 30, 40, 50),
                Arrays.asList(2, 4, 6, 8, 10)
        );
    }

    @ParameterizedTest
    @MethodSource("provideNumberLists")
    void testSum(List<Integer> numbers) {
        int expectedSum = numbers.stream().mapToInt(Integer::intValue).sum();
        assertEquals(expectedSum, MathUtils.sum(numbers));
    }
}

Stream์„ ๋ฐ˜ํ™˜ํ•˜๋Š” static ๋ฉ”์„œ๋“œ๋ฅผ ์ธ์ž๋กœ ๋„˜๊ฒจ์ฃผ์–ด ํ•ด๋‹น ๋ฉ”์„œ๋“œ๋ฅผ ์‹คํ–‰ํ•œ ๊ฒฐ๊ณผ๋ฅผ ํ•˜๋‚˜์”ฉ ์ธ์ž์— ๋„ฃ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด numbers์—๋Š” Arrays.asList(1, 2, 3, 4, 5), Arrays.asList(10, 20, 30, 40, 50), Arrays.asList(2, 4, 6, 8, 10)์˜ ๊ฐ’์ด ํ•˜๋‚˜์”ฉ ๋“ค์–ด๊ฐ€ ์ด 3๋ฒˆ์˜ ํ…Œ์ŠคํŠธ๊ฐ€ ์ˆ˜ํ–‰๋˜๊ฒ ์ฃ ?

์‹ค์ œ๋กœ๋„ ์„ธ ๋ฒˆ์˜ ํ…Œ์ŠคํŠธ๊ฐ€ ์ˆ˜ํ–‰๋˜๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ถ”๊ฐ€์ ์œผ๋กœ ์ธ์ž๋ฅผ ์—ฌ๋Ÿฌ๊ฐœ ๋„˜๊ธฐ๊ณ  ์‹ถ๋‹ค๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด Arguments.arguments๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

static Stream<Arguments> provideNumberLists() {
        return Stream.of(
                Arguments.arguments(Arrays.asList(1, 2, 3, 4, 5), 15),
                Arguments.arguments(Arrays.asList(10, 20, 30, 40, 50), 150),
                Arguments.arguments(Arrays.asList(2, 4, 6, 8, 10), 30)
        );
    }

    @ParameterizedTest
    @MethodSource("provideNumberLists")
    void testSum(List<Integer> numbers, int answer) {
        assertEquals(answer, MathUtils.sum(numbers));
    }

Arguments.arguments๋กœ ๋ฌถ์ธ ๋ถ€๋ถ„์„ ํ•˜๋‚˜์˜ ํ…Œ์ŠคํŠธ๋กœ ๋ณด๋ฉด ๋ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ทธ ์† ์ธ์ž๋“ค์ด ๊ฐ๊ฐ ํ…Œ์ŠคํŠธ ํ•จ์ˆ˜์˜ ์ธ์ž๋กœ ๋“ค์–ด๊ฐ€๊ฒŒ ๋˜๋Š”๋ฐ์š”. Arguments.arguments(Arrays.asList(1, 2, 3, 4, 5), 15)๋ถ€๋ถ„์—์„œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ์ธ์ž์— ๊ฐ’์ด ํ• ๋‹น๋˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

๐Ÿ“š testSumํ•จ์ˆ˜์˜ ์ธ์ž(Arguments.arguments(Arrays.asList(1, 2, 3, 4, 5), 15))
numbers = Arrays.asList(1, 2, 3, 4, 5)
answer = 15

๋งˆ์ง€๋ง‰์œผ๋กœ @ParameterisedTest์— ์ฃผ๋ฉด ์ข‹์€ ์œ ์šฉํ•œ ์ธ์ž๋ฅผ ์†Œ๊ฐœํ•˜๊ณ  ๋งˆ์น˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ๋ฐ”๋กœ name์ด๋ผ๋Š” ์ธ์ž์ธ๋ฐ์š”. ํ˜„์žฌ ์œ„ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋ฅผ ์ˆ˜ํ–‰ํ•˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ๊ฒฐ๊ณผ๊ฐ€ ์ถœ๋ ฅ๋ฉ๋‹ˆ๋‹ค.

๋งŒ์•ฝ @ParameterizedTest์— name์ธ์ž๋ฅผ ์ฃผ๊ฒŒ ๋˜๋ฉด ์ด ๋ถ€๋ถ„์„ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

์•„๋ž˜์™€ ๊ฐ™์ด ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๊ณ  ์‹คํ–‰ํ•ด๋ณด๋ฉด

class MathUtilsTest {

    static Stream<Arguments> provideNumberLists() {
        return Stream.of(
                Arguments.arguments(Arrays.asList(1, 2, 3, 4, 5), 15),
                Arguments.arguments(Arrays.asList(10, 20, 30, 40, 50), 150),
                Arguments.arguments(Arrays.asList(2, 4, 6, 8, 10), 30)
        );
    }

    **@ParameterizedTest(name = "์ฃผ์–ด์ง„ ๊ฐ’ : {0}, ๊ฒฐ๊ณผ : {1}") //name ์ธ์ž ์‚ฌ์šฉ**
    @MethodSource("provideNumberLists")
    void testSum(List<Integer> numbers, int answer) {
        assertEquals(answer, MathUtils.sum(numbers));
    }
}

์•„๋ž˜์™€ ๊ฐ™์ด ํ…Œ์ŠคํŠธ์˜ ์ œ๋ชฉ์ด ๋ฐ”๋€ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๐Ÿ“šReference

https://theamabile.tistory.com/21

 

[์ธํ…”๋ฆฌ์ œ์ด / Intelli J] ์ธํ…”๋ฆฌ์ œ์ด์—์„œ ํ…Œ์ŠคํŠธ ํด๋ž˜์Šค ์ƒ์„ฑ ๋‹จ์ถ•ํ‚ค

์ดํด๋ฆฝ์Šค์—์„œ ์ธํ…”๋ฆฌ์ œ์ด๋กœ ์˜ฎ๊ฒจ์˜ค๋ฉฐ ์ธํ…”๋ฆฌ์ œ์ด์— ์ต์ˆ™ํ•ด์ง€๋Š” ์ค‘์ด๋‹ค ํ…Œ์ŠคํŠธ ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค ์ผ์ด ์žฆ๋‹ค๋ณด๋‹ˆ ์ฐพ์•„๋ณธ ํ…Œ์ŠคํŠธ ํด๋ž˜์Šค ์ƒ์„ฑ ๋ฐฉ๋ฒ•! ๋‹จ์ถ•ํ‚ค 1. ํด๋ž˜์Šค ๋ช… ์„ ํƒ or ํด๋ž˜์Šค ๋‚ด๋ถ€์— ์ปค์„œ

theamabile.tistory.com

https://zzang9ha.tistory.com/344

 

JUnit - @ParameterizedTest, @ValueSource, @CsvSource, @MethodSource ์–ด๋…ธํ…Œ์ด์…˜

• ์•ˆ๋…•ํ•˜์„ธ์š”~ ์ด์ „์— ์šด์˜ํ•˜๋˜ ๋ธ”๋กœ๊ทธ ๋ฐ GitHub, ๊ณต๋ถ€ ๋‚ด์šฉ์„ ์ •๋ฆฌํ•˜๋Š” Study-GitHub ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค! • ๋„ค์ด๋ฒ„ ๋ธ”๋กœ๊ทธ • GitHub • Study-GitHub • ๐Ÿ” ๐Ÿ“Ž JUnit5 - @ParameterizedTest, @ValueSource, @CsvSource, @MethodS

zzang9ha.tistory.com

https://ebabby.tistory.com/28

 

[JUnit] @ParameterizedTest - @MethodSource ์‚ฌ์šฉํ•˜๊ธฐ

๋“ค์–ด๊ฐ€๋ฉฐ ์ด์ „์— 'Parameterized Test - ํ…Œ์ŠคํŠธ๋ฅผ ํšจ์œจ์ ์œผ๋กœ'๋ผ๋Š” ๊ธ€์„ ์˜ฌ๋ ธ์—ˆ๋Š”๋ฐ ์ „๋ถ€ ํ•™์Šตํ•œ ๋‚ด์šฉ์ด ์•„๋‹ˆ๋ผ์„œ ์ด๋ฒˆ์— ์‚ฌ์šฉํ•œ ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€๋กœ ํฌ์ŠคํŒ…ํ•˜๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ์ด์ „์— ๋‹ค๋ค˜๋˜ ํ…Œ์ŠคํŠธ๋Š” ํด๋ž˜์Šค

ebabby.tistory.com

 

๋Œ“๊ธ€