더 자바, 애플리케이션을 테스트하는 다양한 방법

Ch01. JUnit5 - JUnit5 테스트 반복하기

webmaster 2022. 1. 4. 17:24
728x90

JUnit5 테스트 반복하기 

@RepeatedTest

  • 반복되는 테스트를 실행할 때, 사용한다. 

    • parameter로 들어오는 RepotitionInfo에는 총 횟수, 현재 idx 정보가 들어있다.
    • 테스트의 이름을 다양한 방식으로 보여줄 수 있는데 {dispalyName}과 같은 속성을 사용이 가능하다.
    • 해당 형식으로 실행

@ParameterizedTest

  • 글자의 수에 맞게 테스트를 반복할 수 있다.
  • 결과
  • 파라미터로 받는 message에 현재 idx에 해당되는 message가 들어 있다.

JUnit5 테스트 반복하기 2부

https://junit.org/junit5/docs/current/user-guide/#writing-tests-parameterized-tests

 

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

  • 인자 값들의 소스 
    • @ValueSource 
    • @NullSource, @EmptySource, @NullAndEmptySource 
    • @EnumSource 
    • @MethodSource 
    • @CsvSource 
      • 2개 이상의 매개변수를 받을 때,
      • 파라미터를 나눠서 받거나 ArgumentsAccessor를 사용
      • Converter를 재정의 하여 내 Class에 맞도록 변환할 수 있다(매개변수 여러 개 가능)
      • @CsvSource로 2개이상을 매개변수를 전달하여, @AggregateWith 어노테이션으로 구현한 Aggregator를 넣어준다,
    • @CvsFileSource 
    • @ArgumentSource
      • SimpleArgumentConverter 함수 재정의
      • Converter를 재정의 하여 내 Class에 맞도록 변환할 수 있다(단 매개변수가 하나여야 한다)
      • 사용
      • @ValueSource 로 한 개의 값을 받아 @ConvertWith로 변환 방법을 명시해 주면 된다.
728x90