본문 바로가기
  • Code Smell

junit4

[Spring] ActiveProfiles 와 spring.profiles.active 가 일치하지 않는 현상 (ActiveProfiles & spring.profile.active does not match) @ActiveProfiles 와 spring.profiles.active 가 일치하지 않는 현상 테스트코드를 작성할 때 profile 주입을 위해서 아래와 같이 주입하고는 했습니다. 그런데 뭔가 이상한 현상을 발견했는데, 사내 프로젝트 소스에서 profile 에 따른 통합 테스트 진행 시 의도한 바와 같이 진행되지 않는 걸 발견했습니다. 테스트 1) application.yml 프로퍼티 로드 application.yml 에는 profile에 따라 프로퍼티를 override 합니다. 즉 default profile 로 작성된 프로퍼티를 가져오고, 그 뒤 세팅한 profile 값으로 덮어 씌우는 방식입니다. 그래서 아래처럼 테스트를 진행했습니다. 그리고 테스트 프로퍼티를 가져 올 bean을 작성합니다. 그리.. 2022. 8. 7.
[JUnit] JUnit5 사용법과 TDD (2) - REST API 테스트 JUnit5 사용법과 TDD (2) JUnit 5의 dependency 추가 방법과 실행 순서, 기본 annotation에 대한 정리 -> TDD 정리 1 Spring 관련 주요 Test Annotation JUnit5와 spring-boot-test의 모든 annotation은 아니며 자주 사용되는 Annotation만 소개 @ExtendWith(Class[] c) 필요한 Class들을 Configuration 으로 만들어 사용 할 수 있다. (기존 Configuration 클래스도 땡겨 올 수 있다.) Configuration Component이므로 내부에 있는 Bean 까지 등록이 가능하다. Import 된 클래스는 주입으로 사용 가능. @Profile 클래스와 메소드 레벨에서 지정 가능하며, 특정.. 2021. 3. 30.
[JUnit] JUnit5 사용법과 TDD (1) JUnit5 사용법과 TDD (1) 설명 JUnit은 자바의 단위 테스트 프레임워크이다. xUnit에서 파생되어 각 언어별 Unit 프레임워크가 존재한다. C : CUnit C++ : cppUnit Python : pyUnit Java : JUnit 현재 JUnit은 2021년 3월 기준 5버전까지 나온 상태이다. 공식사이트 프로젝트에 추가하기 spring boot 환경(intelliJ, Gradle)에서 추가하였다. JUnit은 spring-boot-starter-test에 기본적으로 포함 되어있다. build.gradle에 spring-boot-starter-test 패키지를 추가하고, 아래 useJUnitPlatform 을 테스트 영역에 작성한다. dependencies { ... implement.. 2021. 3. 19.
[SPRING BOOT] REST API 개발하기 4 - JUnit 테스트 REST API 개발하기 4 - JUnit 테스트 GitHub 소스 test 패키지에서 사용할 수 있도록 spring-boot-starter-test를 implementation으로 바꿔준다. dependencies { implementation('org.projectlombok:lombok') annotationProcessor('org.projectlombok:lombok') implementation('org.springframework.boot:spring-boot-starter') implementation('org.springframework.boot:spring-boot-starter-web') // swagger2 implementa.. 2020. 8. 5.