Skip to content

Instantly share code, notes, and snippets.

@rolroralra
Last active August 24, 2022 02:46
Show Gist options
  • Save rolroralra/4deebc370803f6dd76a1bc9f108bb9b8 to your computer and use it in GitHub Desktop.
Save rolroralra/4deebc370803f6dd76a1bc9f108bb9b8 to your computer and use it in GitHub Desktop.
Junit

ParameterizedTest in JUnit5 (Baeldung)

https://www.baeldung.com/parameterized-tests-junit-5


Mockito (Baeldung)

https://www.baeldung.com/mockito-annotations


ReflectionTestUtils

ReflectionTestUtils 는 Spring Test Context 프레임워크의 일부입니다. 유닛에서 사용되는 리플렉션 기반 유틸리티 메소드 및 비공개 필드를 설정하고 비공개 메소드를 호출하고 종속성을 주입하기 위한 통합 테스트 시나리오에 대한 모음입니다.

https://www.baeldung.com/spring-reflection-test-utils


Mockito (@Mock, @Spy, @Captor, @InjectMocks)

https://codechacha.com/ko/mockito-annotations/


JaCoCo

JaCoCo는 Java 코드의 커버리지를 체크하는 라이브러리입니다. 테스트코드를 돌리고 그 커버리지 결과를 눈으로 보기 좋도록 html이나 xml, csv 같은 리포트로 생성합니다.

https://techblog.woowahan.com/2661/


Parameterized Test (JUnit5)

https://dublin-java.tistory.com/56


MockedStatic

https://www.crocus.co.kr/1705

Details

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.MockedStatic;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
public class CalculatorTest { 
  private static MockedStatic<Calculator> mCalculator; 
  
  @BeforeClass 
  public static void beforeClass() { 
    mCalculator = mockStatic(Calculator.class); 
  } 
  
  @AfterClass 
  public static void afterClass() { 
    mCalculator.close(); 
  } 
  
  @Test 
  public void execute_add() { 
    // Given
    int a = 1, b = 2; 
 
    // When
    when(Calculator.add(anyInt(), anyInt())).thenReturn(a + b);
    int sum = Calculator.add(a, b); 
    
    // Then
    assertEquals(a + b, sum); 
  } 
}


Parameterized Test in JUnit4

https://stackoverflow.com/questions/650894/changing-names-of-parameterized-tests


JUnit5 에서 의존성 주입을 @Autowired로 해야하는 이유

https://pinokio0702.tistory.com/189?category=414017


Mockito

https://jdm.kr/blog/222

https://cobbybb.tistory.com/16


@JdbcTest, @DataJdbcTest, @DataJpaTest

https://pomo0703.tistory.com/100


Suite

https://junit.org/junit5/docs/current/user-guide/#junit-platform-suite-engine

  • Required Dependencies
     dependencies {
     	implementation 'org.junit.platform:junit-platform-suite-engine:1.8.2'
     	testImplementation 'org.junit.platform:junit-platform-suite-api:1.8.2'
     }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment