You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
src/main/kotlin/...에 있는 JVM 모듈 소스(core:domain, core:common)는 src/test/kotlin/...에 둔다.
src/main/java/...에 있는 Android 모듈 소스(app, core:data, core:ui, feature:* 전부)는 src/test/java/...에 둔다.
패키지 경로는 대상 클래스와 동일하게 미러링한다.
Compose UI 테스트(createComposeRule)도 src/androidTest가 아니라 src/test에 두고 Robolectric으로 실행한다.
CI에는 에뮬레이터가 없어서 androidTest는 실행되지 않기 때문이다. 아래 "Robolectric 예외"를 따른다.
네이밍
파일명은 <대상클래스>Test.kt로 쓴다.
테스트 함수명은 백틱으로 감싼 영어 서술형을 쓴다.
Given/When/Then 주석은 쓰지 않고 빈 줄로 구획한다.
@Test
fun`invoke returns success when repository returns route`() = runTest {
val repository = mockk<CourseRepository>()
coEvery { repository.getRoute(course) } returns routeResult
val useCase =GetRouteUseCase(repository)
val result = useCase(course)
assertEquals(routeResult, result.getOrThrow())
}
Robolectric에서 실행하는 테스트(Roborazzi 스크린샷, Compose UI 테스트)는 org.junit.jupiter.api.Test가 아니라
org.junit.Test와 @RunWith(AndroidJUnit4::class)를 사용하는 JUnit4 예외를 적용한다.
Robolectric이 JUnit4 러너 생태계에 묶여 있기 때문이며, junit-vintage-engine으로 JUnit5 플랫폼과
연결한다. 모듈에는 libs.bundles.robolectric.test, testRuntimeOnly(libs.junit.vintage.engine),
testOptions { unitTests.isIncludeAndroidResources = true }가 필요하다.