0807 ~ 0902


# 0807 ~ 0902

# 0808 - Spring Boot ์„ค์ •์— ๋”ฐ๋ฅธ ๋™์  ๋นˆ ์ƒ์„ฑ

์Šค์ผ€์ค„๋Ÿฌ๋ฅผ ์กฐ๊ฑด๋ถ€๋กœ ๋“ฑ๋กํ•˜๊ธฐ ์œ„ํ•ด ํ•™์Šต

# 1. @Value boolean

@Value๋ฅผ ํ†ตํ•ด properties ๊ฐ’์„ ์ฃผ์ž… ๋ฐ›์•„ ์ฒ˜๋ฆฌ(๋™์  ๋นˆ๋“ฑ๋ก์ด๋ž‘์€ ๋ฌด๊ด€)

@Configuration
@EnableScheduling
public class ScheduledJobs {
  @Value("${jobs.enabled:true}")
  private boolean isEnabled;

  @Scheduled(fixedDelay = 60000)
  public void cleanTempDirectory() {
    if(isEnabled) {
      // do work here
    }
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13

# 2. @ConditionalOnProperty

@Configuration
@EnableScheduling
public class ScheduledJobs {
    @Bean
    @ConditionalOnProperty(value = "jobs.enabled", matchIfMissing = true, havingValue = "true")
    public ScheduledJob scheduledJob() {
        return new ScheduledJob();
    }
}
1
2
3
4
5
6
7
8
9

# 3. @Profile

@Profile("prod") // or @Profile("!prod")
@Bean
public ScheduledJob scheduledJob() {
    return new ScheduledJob();
}
1
2
3
4
5

# 4. @Conditional

@Profile ์€ ๋‚ด๋ถ€์ ์œผ๋กœ @Conditional์„ ์‚ฌ์šฉ

public class CustomCondition implements Condition {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        String property = context.getEnvironment().getProperty("jobs.enabled");
        return "prod".equals(property);
    }
}
1
2
3
4
5
6
7
  • property์— "jobs.enabled"์˜ key๊ฐ€ "prod"์ด๋ผ๋ฉด ๋นˆ ๋“ฑ๋ก
@Conditional(CustomCondition.class)
@Bean
public ScheduledJob scheduledJob() {
    return new ScheduledJob();
}
1
2
3
4
5

# 0829 - Load Average

# Load Average๋ž€

Load Average๋ž€ ์–ผ๋งˆ๋‚˜ ๋งŽ์€ ํ”„๋กœ์„ธ์Šค๊ฐ€ ์‹คํ–‰ ์ค‘ ํ˜น์€ ์‹คํ–‰ ๋Œ€๊ธฐ์ค‘์ธ์ง€ ์˜๋ฏธํ•˜๋Š” ์ˆ˜์น˜์ด๋‹ค. ์กฐ๊ธˆ๋” ์ž์„ธํžˆ ๋งํ•ด ํ”„๋กœ์„ธ์Šค ์ƒํƒœ ์ค‘์—์„œ R(Running)๊ณผ D(Uninterruptible waiting)์ƒํƒœ ํ”„๋กœ์„ธ์Šค ๊ฐœ์ˆ˜๋ฅผ 1๋ถ„, 5๋ถ„, 15๋ถ„๋งˆ๋‹ค ํ‰๊ท ๋‚ธ ๊ฐ’์„ ๋งํ•œ๋‹ค. ์ฆ‰, ์‹œ์Šคํ…œ์˜ ๋ถ€ํ•˜๋ฅผ ํ‰๊ท ์น˜๋กœ ์•Œ๋ ค์ฃผ๋Š” ๊ฐ’์ด๋‹ค. ์ผ๋ฐ˜์ ์œผ๋กœ 1๋ถ„ ๊ฐ’๋ณด๋‹ค๋Š” 5๋ถ„, 15๋ถ„์˜ ๊ฐ’์„ ๋งŽ์ด ์‚ฌ์šฉํ•œ๋‹ค.

# ํ”„๋กœ์„ธ์Šค ์ƒํƒœ R(Running)์ด๋ž€?

  • CPU์—์„œ ์ˆ˜ํ–‰์ด๋˜๊ณ  ์žˆ๊ฑฐ๋‚˜ ์‹คํ–‰๊ฐ€๋Šฅํ•œ ์ƒํƒœ๋ฅผ ๋งํ•œ๋‹ค.

# ํ”„๋กœ์„ธ์Šค ์ƒํƒœ D(Uninterruptible waiting)์ด๋ž€?

  • I/O์— ๋Œ€ํ•ด ๋Œ€๊ธฐํ•˜๋Š” ์ƒํƒœ๋กœ ๋‹ค๋ฅธ ์–ด๋–ค์ผ๋„ ํ•  ์ˆ˜ ์—†์Œ์„ ์˜๋ฏธํ•œ๋‹ค.

# Load Average ํ™•์ธ ๋ช…๋ น์–ด

  • Load Average๋Š” uptime ๋ช…๋ น์–ด๋กœ ํ™•์ธ ๊ฐ€๋Šฅํ•˜๋ฉฐ ์ด๋Š” /proc/loadavg ํŒŒ์ผ์„ ์—ด์–ด์„œ ๊ทธ ํŒŒ์ผ์˜ ๋‚ด์šฉ์„ ์ฝ๊ณ  ํ™”๋ฉด์— ์ถœ๋ ฅํ•ด์ฃผ๋Š” ๋ช…๋ น์–ด์ด๋‹ค. Load Average ๊ฐ’์„ ์ง์ ‘ ๊ณ„์‚ฐํ•˜๋Š”๊ฒƒ์€ ์•„๋‹ˆ๊ณ  ์ปค๋„์ด ๋ฏธ๋ฆฌ ์ค€๋น„ํ•ด๋‘” /proc/loadavg ํŒŒ์ผ์„ ์ฝ์–ด์„œ ๋ณด์—ฌ์ฃผ๋Š” ๋ช…๋ น์–ด์ด๋‹ค.
  • uptime ๋ฟ๋งŒ์•„๋‹ˆ๋ผ top, cat /proc/loadavg ์œผ๋กœ ํ™•์ธ ๊ฐ€๋Šฅํ•˜๋‹ค.
  • uptime command
$ uptime 10:23:10 up 3 days, 12:06, 1 user, load average: 1.41, 1.37, 1.35
1
  • ์ฒซ๋ฒˆ์งธ ๊ฐ’ : 1๋ถ„ ๋™์•ˆ์˜ ํ‰๊ท ๊ฐ’
  • ๋‘๋ฒˆ์งธ ๊ฐ’ : 5๋ถ„ ๋™์•ˆ์˜ ํ‰๊ท ๊ฐ’
  • ์„ธ๋ฒˆ์งธ ๊ฐ’ : 15๋ถ„ ๋™์•ˆ์˜ ํ‰๊ท ๊ฐ’

# Load Average ๊ฐ’์˜ ์˜๋ฏธ

  • Load Average ๊ฐ’์€ CPU์˜ ์ฝ”์–ด์ˆ˜์— ๋”ฐ๋ผ์„œ ์ˆซ์ž๊ฐ€ ๋‹ฌ๋ผ์ง€๋ฉฐ ๊ฐ CPU ์ฝ”์–ด๊ฐ€ 100% Load๊ฐ€ ๋ฐœ์ƒํ•  ๊ฒฝ์šฐ, 1์ฝ”์–ด๋Š” ๊ฐ’ 1, 2์ฝ”์–ด๋Š” 2, 4์ฝ”์–ด๋Š” ๊ฐ’ 4๋กœ ํ‘œํ˜„์ด ๋œ๋‹ค. ๋งŒ์•ฝ Load Average๊ฐ€ 4๋ผ๋ฉด, ์‹œ์Šคํ…œ์ด CPU ์ฝ”์–ด 4๊ฐœ๋ฅผ 100% ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๊ฑฐ๋‚˜, CPU ์ฝ”์–ด 1๊ฐœ๋ฅผ 400% ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋‹ค๋Š” ์˜๋ฏธ์ด๋‹ค.
  • ์‹œ์Šคํ…œ ์šด์˜์‹œ ๊ถŒ์žฅํ•˜๋Š” ์—๋ฒ„๋ฆฌ์ง€๋Š” 70%์ธ 0.7 ์ดํ•˜์ด๋ฉฐ ๊ทธ ์ด์ƒ์ผ ๊ฒฝ์šฐ ์‹œ์Šคํ…œ์— ์ด์ƒ์ด ์—†๋Š”์ง€ ๋ฐ˜๋“œ์‹œ ์ฒดํฌํ•ด์•ผ ํ•œ๋‹ค.

# 0831 - AWS ์„œ๋น„์Šค ์ •๋ฆฌ

# EC2

  • AWS์—์„œ ๊ฐ€์žฅ ๊ธฐ๋ณธ์ ์ด๋ฉด์„œ ๋„๋ฆฌ ์“ฐ์ด๋Š” ์ธํ”„๋ผ๋กœ, ๋ฌผ๋ฆฌ ํ™˜๊ฒฝ์˜ ์ปดํ“จํ„ฐ์ฒ˜๋Ÿผย ์ปดํ“จํŒ… ๋ฆฌ์†Œ์Šค๋ฅผ ์ œ๊ณตํ•˜๋Š” ์„œ๋น„์Šค
  • ํด๋ผ์šฐ๋“œ์—์„œ ์ปดํ“จํŒ… ํŒŒ์›Œ์˜ ๊ทœ๋ชจ๋ฅผ ์ž์œ ์ž์žฌ๋กœ ๋ณ€๊ฒฝ ๊ฐ€๋Šฅ
  • ๊ฐ€์ƒ ๋จธ์‹ ์œผ๋กœ ์ œ๊ณต๋˜๋ฉฐย ์ธ์Šคํ„ด์Šค๋ผ๊ณ  ๋ถˆ๋ฆฐ๋‹ค.
  • ์•ˆ์ •์„ฑ์„ ์œ„ํ•ด ์—ฌ๋Ÿฌ AWSย ๋ฆฌ์ „๊ณผ ๊ฐ€์šฉ ์˜์—ญ์— ๊ฑธ์ณ ๋ฐฐํฌ

# AWS Auto Scaling

  • ํŠธ๋ž˜ํ”ฝ์— ๋”ฐ๋ผ EC2 ์ธ์Šคํ„ด์Šค๋“ค์„ย ์ž๋™์œผ๋กœ ํ™•์žฅํ•˜๊ฑฐ๋‚˜ ์ œ๊ฑฐํ•ด์ฃผ๋Š” ์„œ๋น„์Šค
  • ELB์™€ ํ•จ๊ป˜ ์‚ฌ์šฉ๋˜๋Š” ๊ธฐ๋Šฅ์œผ๋กœ ํŠน์ • ํŠธ๋ž˜ํ”ฝ์„ ์ดˆ๊ณผ์‹œ ์ž๋™์œผ๋กœ EC2 ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ๋‹ค์‹œ ํŠธ๋ž˜ํ”ฝ์ด ์ค„์–ด๋“ค๋ฉด ์ถ”๊ฐ€ ์ƒ์„ฑํ•˜์˜€๋˜ EC2 ์ธ์Šคํ„ด์Šค๋“ค์„ ์‚ญ์ œํ•˜๋Š” ์œ ์—ฐํ•œ ์„œ๋น„์Šค๋ฅผ ๊ตฌ์ถ•ํ•  ์ˆ˜ ์žˆ๋„๋ก ๋„์™€์ฃผ๋Š” ์„œ๋น„์Šค

# Lambda (Serverless Computing)

  • ๋ชจ๋“  ์œ ํ˜•์˜ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด๋‚˜ ๋ฐฑ์—”๋“œ ์„œ๋น„์Šค์— ๋Œ€ํ•œ ์ฝ”๋“œ๋ฅผ ๋ณ„๋„์˜ ๊ด€๋ฆฌ ์—†์ด ์‹คํ–‰ํ•˜๋Š” ์„œ๋น„์Šค
  • ์‚ฌ์šฉ์ž๋Š” ์„œ๋ฒ„์— ๋Œ€ํ•œ ๊ฑฑ์ •์—†์ดย ์ฝ”๋“œ๋งŒ์œผ๋กœ ์„œ๋น„์Šค๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค.
  • serverless ์•„ํ‚คํ…์ณย ๊ตฌํ˜„์— ์‚ฌ์šฉ
  • ์„œ๋ฒ„ ๋ฐ ์šด์˜ ์ฒด์ œ ์œ ์ง€ ๋ณด์ˆ˜, ์šฉ๋Ÿ‰ ํ”„๋กœ๋น„์ €๋‹ ๋ฐ ์ž๋™ ํ™•์žฅ, ์ฝ”๋“œ ๋ชจ๋‹ˆํ„ฐ๋ง ๋ฐ ๋กœ๊น…๊ณผ ๊ฐ™์€ ์ปดํ“จํŒ… ๋ฆฌ์†Œ์Šค์˜ ๋ชจ๋“  ๊ด€๋ฆฌ๋ฅผ ์ž์ฒด์ ์œผ๋กœ ์ˆ˜ํ–‰ํ•˜๋ฏ€๋กœ, Lambda๊ฐ€ ์‚ฌ์šฉํ•˜๋Š” ์–ธ์–ด ์ค‘ ํ•˜๋‚˜๋กœ ์ฝ”๋“œ๋ฅผ ์ œ๊ณตํ•˜๊ธฐ๋งŒ ํ•˜๋ฉด ๋œ๋‹ค.

# Lightsail

  • VPS(Virtual Private Server) ์„œ๋น„์Šค
  • ์ฃผ์–ด์ง„ ๋ฆฌ์†Œ์Šค ์˜ต์…˜(Ubuntu, Node, Lamp stack, Nginx, WordPress, Django.. etc) ์ค‘ ํ•˜๋‚˜๋ฅผ ํƒํ•˜์—ฌ ๋‹จ์ผ ๊ฐ€์ƒ ์„œ๋ฒ„๋ฅผ ์‰ฝ๊ฒŒ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.
  • ํ”„๋กœ์ ํŠธ๋ฅผ ๋น ๋ฅด๊ฒŒ ์‹œ์ž‘ํ•˜๋Š” ๋ฐ ํ•„์š”ํ•œ ๊ฐ€์ƒ๋จธ์‹ , SSD๊ธฐ๋ฐ˜ ์Šคํ† ๋ฆฌ์ง€, ๋ฐ์ดํ„ฐ ์ „์†ก, DNS๊ด€๋ฆฌ, ์ •์ IP๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ๋‹ค.

# ECS(Elastic Container Service)

  • ํด๋ผ์šฐ๋“œ ์„œ๋ฒ„์ธ EC2๋ฅผย Docker ์ปจํ…Œ์ด๋„ˆ๋กœ ๊ด€๋ฆฌย ๊ฐ€๋Šฅํ•˜๋„๋ก ๋‚˜์˜จ ์„œ๋น„์Šค
  • ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹คํ–‰ํ•˜๋Š” ๊ณ ๋„๋กœ ์•ˆ์ „ํ•˜๊ณ , ์•ˆ์ •์ ์ด๊ณ , ํ™•์žฅ ๊ฐ€๋Šฅํ•œ ๋ฐฉ์‹์ด๋‹ค.
  • AWS Fargate ์‚ฌ์šฉ๊ฐ€๋Šฅ
    • AWS Fargate๋Š” ๋ณ„๋„๋กœ ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑ ๊ด€๋ฆฌํ•˜์ง€ ์•Š๊ณ , ์™„์ „ํ•œ ๋งค๋‹ˆ์ง€๋“œ ์„œ๋น„์Šค์˜ ํ˜•ํƒœ๋กœ ๋„์ปค ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹คํ–‰์‹œํ‚ฌ ์ˆ˜ ์žˆ๋Š” ์•„๋งˆ์กด์˜ ์„œ๋น„๋ฆฌ์Šค ์ปจํ…Œ์ด๋„ˆ ์ƒํ’ˆ์ด๋‹ค.ย Dockerย ์ด๋ฏธ์ง€๊ฐ€ ๋ฆฌํŒŒ์ง€ํ„ฐ๋ฆฌ์— ํ‘ธ์‹œ๋˜์–ด ์žˆ๋‹ค๋ฉด,ย ํด๋Ÿฌ์Šคํ„ฐย โ†’ย ์ž‘์—… ์ •์˜ย โ†’ย ์„œ๋น„์Šค์˜ ์ˆœ์„œ๋กœ ์ƒ์„ฑํ•˜์—ฌ ์™„์ „ํžˆ 24์‹œ๊ฐ„ ์„œ๋น„์Šค ๊ฐ€๋Šฅํ•œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๊ธฐ๋™ํ•  ์ˆ˜ ์žˆ๋‹ค

# EB(Elastic Beanstalk)

  • Java, .NET, PHP, Node.js, Python, Ruby, Go, Docker๋ฅผ ์‚ฌ์šฉํ•˜์—ฌย Apache, Nginx, Passenger, IIS์™€ ๊ฐ™์€ ์นœ์ˆ™ํ•œ ์„œ๋ฒ„์—์„œ ๊ฐœ๋ฐœ๋œย ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ฐ ์„œ๋น„์Šค๋ฅผ ๊ฐ„ํŽธํ•˜๊ฒŒ ๋ฐฐํฌํ•˜๊ณ  ์กฐ์ •ํ•  ์ˆ˜ ์žˆ๋Š” ์„œ๋น„์Šค

# CodeDeploy

  • Amazon EC2 ์ธ์Šคํ„ด์Šค, ์˜จํ”„๋ ˆ๋ฏธ์Šค ์ธ์Šคํ„ด์Šค, ์„œ๋ฒ„๋ฆฌ์Šค Lambda ํ•จ์ˆ˜ ๋˜๋Š” Amazon ECS ์„œ๋น„์Šค๋กœ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ฐฐํฌ๋ฅผ ์ž๋™ํ™”ํ•˜๋Š” ๋ฐฐํฌ ์„œ๋น„์Šค
  • CodeDeploy๋Š” ์„œ๋ฒ„์—์„œ ์‹คํ–‰๋˜๊ณ  Amazon S3 ๋ฒ„ํ‚ท, GitHub ๋ฆฌํฌ์ง€ํ† ๋ฆฌ ๋˜๋Š” Bitbucket ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์— ์ €์žฅ๋˜๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ฝ˜ํ…์ธ ๋ฅผ ๋ฐฐํฌํ•  ์ˆ˜ ์žˆ๋‹ค. ๋˜ํ•œ CodeDeploy๋Š” ์„œ๋ฒ„๋ฆฌ์Šค Lambda ํ•จ์ˆ˜๋ฅผ ๋ฐฐํฌํ•  ์ˆ˜ ์žˆ๋‹ค. CodeDeploy๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ๊ธฐ์กด ์ฝ”๋“œ๋ฅผ ๋ณ€๊ฒฝํ•  ํ•„์š”๊ฐ€ ์—†๋‹ค

# ECR(Elastic Container Registry)

  • AWS์—์„œ ์ œ๊ณตํ•˜๋Š” Docker Hub์™€ ๋น„์Šทํ•œ ๊ฐœ๋…์œผ๋กœ,ย Amazon Elastic Container Registry์˜ ์•ฝ์ž๋กœ ์•ˆ์ „ํ•˜๊ณ  ํ™•์žฅ ๊ฐ€๋Šฅํ•˜๊ณ  ์‹ ๋ขฐํ•  ์ˆ˜ ์žˆ๋Š” AWS ๊ด€๋ฆฌํ˜• ์ปจํ…Œ์ด๋„ˆ ์ด๋ฏธ์ง€ ๋ ˆ์ง€์ŠคํŠธ๋ฆฌ ์„œ๋น„์Šค
  • Amazon ECR์€ AWS IAM์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฆฌ์†Œ์Šค ๊ธฐ๋ฐ˜ ๊ถŒํ•œ์„ ๊ฐ€์ง„ ํ”„๋ผ์ด๋น— ๋ฆฌํฌ์ง€ํ† ๋ฆฌ๋ฅผ ์ง€์›
  • Docker Hub์™€ ๋™์ผํ•˜๋‹ค๊ณ  ๋ณผ ์ˆ˜ ์žˆ์ง€๋งŒ ์žฅ์ ์œผ๋กœ๋Š”ย S3๋กœ Docker Image๋ฅผ ๊ด€๋ฆฌํ•˜๋ฏ€๋กœ ๊ณ ๊ฐ€์šฉ์„ฑ์„ ๋ณด์žฅํ•˜๊ณ , AWS IAM ์ธ์ฆ์„ ํ†ตํ•ด ์ด๋ฏธ์ง€ push/pull์— ๋Œ€ํ•œ ๊ถŒํ•œ ๊ด€๋ฆฌ๊ฐ€ ๊ฐ€๋Šฅ

# 0901 - Mockito์™€ BDDMockito ์ฐจ์ด

# Mockito

  • Mock ๊ฐ์ฒด๋ž€? ์‹ค์ œ ์‚ฌ์šฉํ•˜๋Š” ๋ชจ๋“ˆ์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ์‹ค์ œ์˜ ๋ชจ๋“ˆ์„ "ํ‰๋‚ด"๋‚ด๋Š” "๊ฐ€์งœ" ๋ชจ๋“ˆ์„ ์ž‘์„ฑํ•˜์—ฌ ํ…Œ์ŠคํŠธ์˜ ํšจ์šฉ์„ฑ์„ ๋†’์ด๋Š” ๋ฐ ์‚ฌ์šฉํ•˜๋Š” ๊ฐ์ฒด
  • Mock ๊ฐ์ฒด๋ฅผ ์‰ฝ๊ฒŒ ๋งŒ๋“ค๊ณ , ๊ด€๋ฆฌํ•˜๊ณ , ๊ฒ€์ฆํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์„ ์ œ๊ณตํ•˜๋Š” ํ”„๋ ˆ์ž„์›Œํฌ
  • @ExtendWith(MockitoExtension.class) ์„ ์–ธ
@Test
void hasSkill_AlwaysTrue() {
    // given
    when(skills.hasSkill()).thenReturn(true);

    // when
    boolean actual = person.hasSkill();

    // then
    assertThat(actual).isTrue();
}
1
2
3
4
5
6
7
8
9
10
11

# BDDMockito

BDDMockito provides BDD aliases for various Mockito methods, so we can write our Arrange step using given (instead of when), likewise, we could write our Assert step using then (instead of verify) -ย Quick Guide to BDDMockito(Baeldung) (opens new window)

  • BDD๋ž€? Behavior-Driven Development์˜ ์•ฝ์ž๋กœย ํ–‰์œ„ ์ฃผ๋„ ๊ฐœ๋ฐœ์„ ๋งํ•œ๋‹ค. ํ…Œ์ŠคํŠธ ๋Œ€์ƒ์˜ย ์ƒํƒœ์˜ ๋ณ€ํ™”๋ฅผ ํ…Œ์ŠคํŠธํ•˜๋Š” ๊ฒƒ์ด๊ณ , ์‹œ๋‚˜๋ฆฌ์˜ค๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํ…Œ์ŠคํŠธํ•˜๋Š” ํŒจํ„ด์„ ๊ถŒ์žฅํ•œ๋‹ค
  • ์—ฌ๊ธฐ์„œ ๊ถŒ์žฅํ•˜๋Š” ๊ธฐ๋ณธ ํŒจํ„ด์€ย Given, When, Then ๊ตฌ์กฐ๋ฅผ ๊ฐ€์ง„๋‹ค
  • BDDMockito์˜ ์ฝ”๋“œ๋ฅผ ์‚ดํŽด๋ณด๋ฉดย Mockito์„ ์ƒ์†ํ•œ ํด๋ž˜์Šค์ž„์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๋™์ž‘์ด๋‚˜ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ• ๋˜ํ•œย Mockito์™€ ๊ฑฐ์˜ ์ฐจ์ด๊ฐ€ ์—†๋‹ค.
    • Mockito์˜ย when()ย ๋ฉ”์„œ๋“œ๊ฐ€ ์•„๋‹Œย given()ย ๋ฉ”์„œ๋“œ
    • Mockito์—์„œ ์ œ๊ณตํ•˜๋Š”ย verify()ย ๋„ย then().should()ย ๋กœ ๋Œ€์ฒด
  • Mockito์˜ ๊ฐ€๋…์„ฑ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•œย ๊ธฐ๋Šฅ์€ ๊ฐ™์ง€๋งŒ ์ด๋ฆ„๋งŒ ๋‹ค๋ฅธ ํด๋ž˜์Šค
@Test
void hasSkill_AlwaysTrue() {
    // given
    given(skills.hasSkill()).willReturn(true);

    // when
    boolean actual = person.hasSkill();

    // then
    assertThat(actual).isTrue();
}
1
2
3
4
5
6
7
8
9
10
11
Last update: September 5, 2023 23:23
Contributors: jaesungahn91