Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,11 @@ 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")

extensions.configure<LibraryExtension> {
configureCompose(this)
}

dependencies {
val bom = platform(libs.library("compose-bom"))
implementation(bom)
implementation(libs.bundle("compose"))
debugImplementation(libs.bundle("compose-debug"))
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
})
Original file line number Diff line number Diff line change
@@ -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"))
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class FeatureConventionPlugin : BuildLogicConventionPlugin({
apply<AndroidLibraryConventionPlugin>()
apply<KoinConventionPlugin>()
apply<AndroidComposeConventionPlugin>()
apply<AndroidTestConventionPlugin>()

dependencies {
implementation(project(":core:design-system"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
8 changes: 8 additions & 0 deletions core/test/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins {
alias(libs.plugins.twix.java.library)
}

dependencies {
api(libs.kotlinx.coroutines.test)
api(libs.junit.jupiter)
}
25 changes: 25 additions & 0 deletions core/test/src/main/java/com/twix/test/CoroutinesTestExtension.kt
Original file line number Diff line number Diff line change
@@ -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()
}
}
Empty file.
26 changes: 26 additions & 0 deletions feature/login/src/test/java/com/twix/login/ExampleTest.kt
Original file line number Diff line number Diff line change
@@ -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!"
}
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ include(":core:ui")
include(":core:navigation")
include(":core:design-system")
include(":core:network")
include(":core:test")