테스트 코드가 늘어날수록 테스트 수행 시간이 길어지고 있어서 테스트들을 병렬로 수행하기로 했다.

 

1. junit-platform.properties 파일 생성

우선 resources 폴더 아래에 junit-platform.properties 파일을 생성한다.

 

병렬 테스트를 위한 옵션으로 다음과 같이 지정해줄 수 있다. 하나씩 살펴보자

junit.jupiter.execution.parallel.enabled=true
junit.jupiter.execution.parallel.mode.default=CONCURRENT
junit.jupiter.execution.parallel.config.strategy=fixed
junit.jupiter.execution.parallel.config.fixed.parallelism=4

 

  • junit.jupiter.execution.parallel.enabled : 병렬 실행을 사용하기 위해서 enabled를 true로 설정해준다.
  • junit.jupiter.execution.parallel.mode.default : 병렬 실행 모드를 지정한다.
  • junit.jupiter.execution.parallel.config.strategy : 병렬 수행 전략을 선택할 수 있다.
    • dynamic : 사용 가능한 프로세서 코어수에 junit.jupiter.execution.parallel.config.dynamic.factor 구성 매개변수를 곱한 값을 기반으로 원하는 병렬도를 계산한다. (기본값은 1).
    • fixed : junit.jupiter.execution.parallel.config.fixed.parallelism에 설정한 값으로 병렬 처리한다. 4로 설정하면 총 4개의 테스트가 동시에 수행된다고 생각하면 된다.
  • junit.jupiter.execution.parallel.config.fixed.parallelism : 위의 strategy 설명에 써놓은거처럼 설정한 값으로 병렬 처리를 수행한다.

 

참고로 "junit.jupiter.execution.parallel.enabled=true" 옵션만 true로 설정 후 병렬로 테스트할 클래스에 @Execution(ExecutionMode.CONCURRENT)을 붙여서, 어노테이션을 붙인 클래스만 병렬로 수행할 수 있게도 구성할 수 있다.

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;

@Execution(ExecutionMode.CONCURRENT)
public class ParrallelTest {

    @Test
    @DisplayName("병렬 테스트 1")
    public void test1() throws Exception {
        Thread.sleep(4000);
    }

    @Test
    @DisplayName("병렬 테스트 2")
    public void test2() throws Exception {
        Thread.sleep(4000);
    }

    @Test
    @DisplayName("병렬 테스트 3")
    public void test3() throws Exception {
        Thread.sleep(4000);
    }

}

 

 

자세한 내용은 공식 가이드를 참고하면 좋을꺼 같다.https://junit.org/junit5/docs/snapshot/user-guide/index.html#writing-tests-parallel-execution

 

JUnit 5 User Guide

Although the JUnit Jupiter programming model and extension model will not support JUnit 4 features such as Rules and Runners natively, it is not expected that source code maintainers will need to update all of their existing tests, test extensions, and cus

junit.org

 

  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기