diff --git a/build-logic/convention/build.gradle.kts b/build-logic/convention/build.gradle.kts index 289fe7d..96c9a25 100644 --- a/build-logic/convention/build.gradle.kts +++ b/build-logic/convention/build.gradle.kts @@ -35,6 +35,10 @@ gradlePlugin { id = "twix.android.compose" implementationClass = "com.twix.convention.AndroidComposeConventionPlugin" } + register("androidTest"){ + id = "twix.android.test" + implementationClass = "com.twix.convention.AndroidTestConventionPlugin" + } register("feature"){ id = "twix.feature" implementationClass = "com.twix.convention.FeatureConventionPlugin" diff --git a/build-logic/convention/src/main/kotlin/com/twix/convention/AndroidComposeConventionPlugin.kt b/build-logic/convention/src/main/kotlin/com/twix/convention/AndroidComposeConventionPlugin.kt index 337b91e..e556b0e 100644 --- a/build-logic/convention/src/main/kotlin/com/twix/convention/AndroidComposeConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/com/twix/convention/AndroidComposeConventionPlugin.kt @@ -3,7 +3,6 @@ package com.twix.convention import com.android.build.api.dsl.LibraryExtension import com.twix.convention.extension.* import org.gradle.kotlin.dsl.configure -import org.gradle.kotlin.dsl.dependencies class AndroidComposeConventionPlugin : BuildLogicConventionPlugin({ applyPlugins("org.jetbrains.kotlin.plugin.compose") @@ -11,11 +10,4 @@ class AndroidComposeConventionPlugin : BuildLogicConventionPlugin({ extensions.configure { configureCompose(this) } - - dependencies { - val bom = platform(libs.library("compose-bom")) - implementation(bom) - implementation(libs.bundle("compose")) - debugImplementation(libs.bundle("compose-debug")) - } }) diff --git a/build-logic/convention/src/main/kotlin/com/twix/convention/AndroidLibraryConventionPlugin.kt b/build-logic/convention/src/main/kotlin/com/twix/convention/AndroidLibraryConventionPlugin.kt index 6920738..24cfdf1 100644 --- a/build-logic/convention/src/main/kotlin/com/twix/convention/AndroidLibraryConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/com/twix/convention/AndroidLibraryConventionPlugin.kt @@ -19,7 +19,5 @@ class AndroidLibraryConventionPlugin : BuildLogicConventionPlugin({ dependencies { implementation(libs.library("kotlinx-coroutines-core")) - testImplementation(libs.bundle("test-unit")) - androidTestImplementation(libs.library("androidx-test-ext-junit")) } }) diff --git a/build-logic/convention/src/main/kotlin/com/twix/convention/AndroidTestConventionPlugin.kt b/build-logic/convention/src/main/kotlin/com/twix/convention/AndroidTestConventionPlugin.kt new file mode 100644 index 0000000..39699e6 --- /dev/null +++ b/build-logic/convention/src/main/kotlin/com/twix/convention/AndroidTestConventionPlugin.kt @@ -0,0 +1,11 @@ +package com.twix.convention + +import com.twix.convention.extension.* +import org.gradle.kotlin.dsl.dependencies + +class AndroidTestConventionPlugin : BuildLogicConventionPlugin({ + dependencies { + testImplementation(libs.bundle("test-unit")) + androidTestImplementation(libs.library("androidx-test-ext-junit")) + } +}) diff --git a/build-logic/convention/src/main/kotlin/com/twix/convention/FeatureConventionPlugin.kt b/build-logic/convention/src/main/kotlin/com/twix/convention/FeatureConventionPlugin.kt index 1f56f4c..42f28a4 100644 --- a/build-logic/convention/src/main/kotlin/com/twix/convention/FeatureConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/com/twix/convention/FeatureConventionPlugin.kt @@ -8,6 +8,7 @@ class FeatureConventionPlugin : BuildLogicConventionPlugin({ apply() apply() apply() + apply() dependencies { implementation(project(":core:design-system")) diff --git a/build-logic/convention/src/main/kotlin/com/twix/convention/extension/DependencyHandlerScopeExtension.kt b/build-logic/convention/src/main/kotlin/com/twix/convention/extension/DependencyHandlerScopeExtension.kt index fe7303f..bd2ad45 100644 --- a/build-logic/convention/src/main/kotlin/com/twix/convention/extension/DependencyHandlerScopeExtension.kt +++ b/build-logic/convention/src/main/kotlin/com/twix/convention/extension/DependencyHandlerScopeExtension.kt @@ -20,6 +20,10 @@ fun DependencyHandlerScope.androidTestImplementation(provider: Provider<*>) { "androidTestImplementation"(provider) } +fun DependencyHandlerScope.testImplementation(project: Project) { + "testImplementation"(project) +} + fun DependencyHandlerScope.testImplementation(provider: Provider<*>) { "testImplementation"(provider) } diff --git a/core/test/build.gradle.kts b/core/test/build.gradle.kts new file mode 100644 index 0000000..cd3cad4 --- /dev/null +++ b/core/test/build.gradle.kts @@ -0,0 +1,8 @@ +plugins { + alias(libs.plugins.twix.java.library) +} + +dependencies { + api(libs.kotlinx.coroutines.test) + api(libs.junit.jupiter) +} diff --git a/core/test/src/main/java/com/twix/test/CoroutinesTestExtension.kt b/core/test/src/main/java/com/twix/test/CoroutinesTestExtension.kt new file mode 100644 index 0000000..1a9b94c --- /dev/null +++ b/core/test/src/main/java/com/twix/test/CoroutinesTestExtension.kt @@ -0,0 +1,25 @@ +package com.twix.test + +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.test.TestDispatcher +import kotlinx.coroutines.test.UnconfinedTestDispatcher +import kotlinx.coroutines.test.resetMain +import kotlinx.coroutines.test.setMain +import org.junit.jupiter.api.extension.AfterEachCallback +import org.junit.jupiter.api.extension.BeforeEachCallback +import org.junit.jupiter.api.extension.ExtensionContext + +@ExperimentalCoroutinesApi +class CoroutinesTestExtension( + private val testDispatcher: TestDispatcher = UnconfinedTestDispatcher(), +) : BeforeEachCallback, + AfterEachCallback { + override fun beforeEach(context: ExtensionContext?) { + Dispatchers.setMain(testDispatcher) + } + + override fun afterEach(context: ExtensionContext?) { + Dispatchers.resetMain() + } +} diff --git a/feature/login/src/test/java/com/twix/login/.gitkeep b/feature/login/src/test/java/com/twix/login/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/feature/login/src/test/java/com/twix/login/ExampleTest.kt b/feature/login/src/test/java/com/twix/login/ExampleTest.kt new file mode 100644 index 0000000..954bb51 --- /dev/null +++ b/feature/login/src/test/java/com/twix/login/ExampleTest.kt @@ -0,0 +1,26 @@ +package com.twix.login + +import com.twix.test.CoroutinesTestExtension +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.test.runTest +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith + +@OptIn(ExperimentalCoroutinesApi::class) +@ExtendWith(CoroutinesTestExtension::class) +class ExampleTest { + @Test + fun `코루틴 테스트 예제`() = + runTest { + // Given + val expected = "Hello, Coroutines!" + + // When + val actual = suspendFunction() + + // Then + assert(actual == expected) + } + + private suspend fun suspendFunction(): String = "Hello, Coroutines!" +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 7cc8770..0f86776 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -173,6 +173,7 @@ android-library = { id = "com.android.library", version.ref = "agp" } twix-android-application = { id = "twix.android.application", version = "unspecified" } twix-android-library = { id = "twix.android.library", version = "unspecified" } twix-android-compose = { id = "twix.android.compose", version = "unspecified" } +twix-android-test = { id = "twix.android.test", version = "unspecified" } twix-feature = { id = "twix.feature", version = "unspecified" } twix-koin = { id = "twix.koin", version = "unspecified" } twix-java-library = { id = "twix.java.library", version = "unspecified" } diff --git a/settings.gradle.kts b/settings.gradle.kts index 9cc7038..9d19157 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -34,3 +34,4 @@ include(":core:ui") include(":core:navigation") include(":core:design-system") include(":core:network") +include(":core:test")