Skip to content

Commit e27e812

Browse files
committed
Merge remote-tracking branch 'origin/develop' into fix/#350-fix-job-filtering-button
2 parents ee8dbb0 + 6c04248 commit e27e812

9 files changed

Lines changed: 140 additions & 1 deletion

File tree

File renamed without changes.

core/testing/build.gradle.kts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import com.terning.build_logic.extension.setNamespace
2+
3+
plugins {
4+
alias(libs.plugins.terning.library)
5+
}
6+
7+
android {
8+
setNamespace("testing")
9+
}
10+
11+
dependencies {
12+
api(libs.kotlinx.coroutines.test)
13+
api(libs.hilt.android.testing)
14+
api(libs.mockito.kotlin)
15+
api(libs.coroutines.test)
16+
17+
implementation(libs.androidx.test.rules)
18+
implementation(libs.hilt.android.testing)
19+
20+
testImplementation(libs.bundles.androidx.compose.ui.test)
21+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
</manifest>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.terning.testing.util
2+
3+
import kotlinx.coroutines.Dispatchers
4+
import kotlinx.coroutines.ExperimentalCoroutinesApi
5+
import kotlinx.coroutines.test.TestDispatcher
6+
import kotlinx.coroutines.test.UnconfinedTestDispatcher
7+
import kotlinx.coroutines.test.resetMain
8+
import kotlinx.coroutines.test.setMain
9+
import org.junit.rules.TestWatcher
10+
import org.junit.runner.Description
11+
12+
@OptIn(ExperimentalCoroutinesApi::class)
13+
class MainDispatcherRule(
14+
private val testDispatcher: TestDispatcher = UnconfinedTestDispatcher(),
15+
) : TestWatcher() {
16+
override fun starting(description: Description) = Dispatchers.setMain(testDispatcher)
17+
18+
override fun finished(description: Description) = Dispatchers.resetMain()
19+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.terning.testing
2+
3+
import org.junit.Test
4+
5+
import org.junit.Assert.*
6+
7+
/**
8+
* Example local unit test, which will execute on the development machine (host).
9+
*
10+
* See [testing documentation](http://d.android.com/tools/testing).
11+
*/
12+
class ExampleUnitTest {
13+
@Test
14+
fun addition_isCorrect() {
15+
assertEquals(4, 2 + 2)
16+
}
17+
}

feature/intern/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ dependencies {
1414

1515
// feature
1616
implementation(projects.feature.dialog)
17+
18+
testImplementation(projects.core.testing)
1719
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.terning.intern
2+
3+
import com.terning.core.designsystem.state.UiState
4+
import com.terning.domain.intern.entity.InternInfo
5+
import com.terning.domain.intern.repository.InternRepository
6+
import com.terning.feature.intern.InternViewModel
7+
import com.terning.testing.util.MainDispatcherRule
8+
import junit.framework.TestCase.assertEquals
9+
import junit.framework.TestCase.assertTrue
10+
import kotlinx.coroutines.flow.first
11+
import kotlinx.coroutines.test.runTest
12+
import org.junit.Before
13+
import org.junit.Rule
14+
import org.junit.Test
15+
import org.mockito.Mockito.doReturn
16+
import org.mockito.Mockito.mock
17+
18+
class InternViewModelTest {
19+
20+
@get:Rule
21+
val mainDispatcherRule = MainDispatcherRule()
22+
23+
private lateinit var viewModel: InternViewModel
24+
private val internRepository: InternRepository = mock()
25+
26+
@Before
27+
fun setUp() {
28+
viewModel = InternViewModel(internRepository)
29+
}
30+
31+
@Test
32+
fun `getInternInfo 성공 시 UiState_Success 설정`() = runTest {
33+
val mockInternInfo = InternInfo(
34+
dDay = "10",
35+
title = "테스트 제목",
36+
deadline = "테스트 내용",
37+
workingPeriod = "3",
38+
startYearMonth = "2023.01",
39+
scrapCount = 10,
40+
viewCount = 10,
41+
company = "테스트 제목",
42+
companyCategory = "테스트 내용",
43+
companyImage = "테스트 내용",
44+
qualification = "테스트 내용",
45+
jobType = "테스트 내용",
46+
detail = "테스트 내용",
47+
url = "테스트 내용",
48+
isScrapped = true
49+
)
50+
51+
doReturn(Result.success(mockInternInfo))
52+
.`when`(internRepository).getInternInfo(1)
53+
54+
viewModel.getInternInfo(1)
55+
56+
val uiState = viewModel.internUiState.first()
57+
assertTrue(uiState.loadState is UiState.Success)
58+
assertEquals((uiState.loadState as UiState.Success).data, mockInternInfo)
59+
}
60+
61+
}

gradle/libs.versions.toml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ lifecycleRuntimeKtx = "2.6.1"
7878
foundationAndroid = "1.6.8"
7979
material3Android = "1.2.1"
8080
lifecycleRuntimeComposeAndroid = "2.8.2"
81+
mockito = "5.10.0"
82+
mockito-inline = "5.2.0"
83+
androidxTestRules = "1.6.1"
84+
8185

8286
## Kakao
8387
kakaoVersion = "2.20.1"
@@ -136,6 +140,7 @@ androidx-compose-saveable = { group = "androidx.compose.runtime", name = "runtim
136140
androidx-ui = { group = "androidx.compose.ui", name = "ui" }
137141
androidx-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
138142
androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
143+
androidx-test-rules = { group = "androidx.test", name = "rules", version.ref = "androidxTestRules" }
139144
androidx-foundation-android = { group = "androidx.compose.foundation", name = "foundation-android", version.ref = "foundationAndroid" }
140145
androidx-material3-android = { group = "androidx.compose.material3", name = "material3-android", version.ref = "material3Android" }
141146
androidx-lifecycle-runtime-compose-android = { group = "androidx.lifecycle", name = "lifecycle-runtime-compose-android", version.ref = "lifecycleRuntimeComposeAndroid" }
@@ -175,6 +180,8 @@ coroutines-android = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutin
175180
coroutines-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-test", version.ref = "coroutine" }
176181
kotlin = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib", version.ref = "kotlin" }
177182
kotlin-gradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
183+
kotlin-test = { group = "org.jetbrains.kotlin", name = "kotlin-test", version.ref = "kotlin" }
184+
kotlinx-coroutines-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-test", version.ref = "coroutine" }
178185
kotlin-collections-immutable = { group = "org.jetbrains.kotlinx", name = "kotlinx-collections-immutable", version.ref = "kotlinx-collections-immutable" }
179186
compose-compiler-extension = { module = "org.jetbrains.kotlin:compose-compiler-gradle-plugin", version.ref = "kotlin" }
180187

@@ -183,6 +190,9 @@ coil-network-okhttp = { module = "io.coil-kt.coil3:coil-network-okhttp", version
183190
kotest-runner = { group = "io.kotest", name = "kotest-runner-junit5", version.ref = "kotest" }
184191
kotest-assertions = { group = "io.kotest", name = "kotest-assertions-core", version.ref = "kotest" }
185192
androidx-test-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCoreVersion" }
193+
mockito-core = { group = "org.mockito", name = "mockito-core", version.ref = "mockito" }
194+
mockito-inline = { group = "org.mockito", name = "mockito-inline", version.ref = "mockito-inline" }
195+
mockito-kotlin = { group = "org.mockito.kotlin", name = "mockito-kotlin", version = "5.1.0" }
186196

187197
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
188198
timber = { module = "com.jakewharton.timber:timber", version.ref = "timber" }
@@ -204,7 +214,7 @@ firebase-bom = { module = "com.google.firebase:firebase-bom", version.ref = "fir
204214
firebase-messaging = { group = "com.google.firebase", name = "firebase-messaging-ktx", version.ref = "firebaseMessaging" }
205215

206216
[bundles]
207-
retrofit =[
217+
retrofit = [
208218
"retrofit-core",
209219
"retrofit-kotlin-serialization",
210220
"retrofit2-kotlinx-serialization-converter"
@@ -213,6 +223,10 @@ okhttp = [
213223
"okhttp",
214224
"okhttp-logging"
215225
]
226+
androidx-compose-ui-test = [
227+
"androidx-compose-ui-test",
228+
"androidx-compose-ui-testManifest"
229+
]
216230

217231
[plugins]
218232
android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" }

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,4 @@ include(
8181
":feature:onboarding",
8282
":feature:search"
8383
)
84+
include(":core:testing")

0 commit comments

Comments
 (0)