Skip to content

Commit 4d58a84

Browse files
authored
Merge pull request #120 from uswLectureEvaluation/feature/#89-timetable-migration-test
Feature/#89 시간표 데이터베이스 마이그레이션 테스트 코드 작성
2 parents 71a4837 + 6b9361f commit 4d58a84

File tree

12 files changed

+83
-38
lines changed

12 files changed

+83
-38
lines changed

Diff for: build-logic/convention/src/main/java/DataConventionPlugin.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ internal class DataConventionPlugin : Plugin<Project> {
1818

1919
"implementation"(libs.findBundle("coroutine").get())
2020

21-
"androidTestImplementation"(libs.findLibrary("junit").get())
21+
"androidTestImplementation"(libs.findLibrary("junit4").get())
2222
"implementation"(libs.findLibrary("timber").get())
2323
}
2424
}

Diff for: build-logic/convention/src/main/java/FeatureComposeConventionPlugin.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ internal class FeatureComposeConventionPlugin : Plugin<Project> {
2626
"implementation"(libs.findLibrary("kotlinx.coroutines.android").get())
2727
"implementation"(libs.findLibrary("kotlinx.coroutines.core").get())
2828

29-
"androidTestImplementation"(libs.findLibrary("junit").get())
29+
"androidTestImplementation"(libs.findLibrary("junit4").get())
3030
"implementation"(libs.findLibrary("timber").get())
3131
}
3232
}

Diff for: build-logic/convention/src/main/java/RemoteConventionPlugin.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal class RemoteConventionPlugin : Plugin<Project> {
1919

2020
"implementation"(libs.findBundle("coroutine").get())
2121

22-
"androidTestImplementation"(libs.findLibrary("junit").get())
22+
"androidTestImplementation"(libs.findLibrary("junit4").get())
2323
"implementation"(libs.findLibrary("timber").get())
2424
}
2525
}

Diff for: build-logic/convention/src/main/java/com/kunize/convention/KotlinAndroid.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ internal fun Project.configureKotlinAndroid(
1414
defaultConfig {
1515
minSdk = Const.minSdk
1616

17-
testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
17+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
1818
vectorDrawables.useSupportLibrary = true
1919
}
2020

Diff for: core/database/build.gradle.kts

+9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ ksp {
1313

1414
android {
1515
namespace = "com.suwiki.core.database"
16+
17+
sourceSets {
18+
// Adds exported schema location as test app assets.
19+
getByName("androidTest").assets.srcDir("$rootDir/schemas")
20+
}
1621
}
1722

1823
protobuf {
@@ -36,11 +41,15 @@ dependencies {
3641
ksp(libs.room.compiler)
3742
implementation(libs.room.runtime)
3843
implementation(libs.room.ktx)
44+
androidTestImplementation(libs.room.testing)
3945

4046
implementation(libs.bundles.coroutine)
4147
implementation(libs.androidx.datastore.core)
4248
implementation(libs.androidx.datastore.preferences)
4349
implementation(libs.protobuf.kotlin.lite)
4450

4551
implementation(libs.kotlinx.serialization.json)
52+
53+
androidTestImplementation(libs.androidx.junit.ktx)
54+
androidTestImplementation(libs.androidx.test.runner)
4655
}

Diff for: core/database/src/androidTest/java/com/suwiki/database/ExampleInstrumentedTest.kt

-22
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.suwiki.database
2+
3+
import androidx.room.testing.MigrationTestHelper
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
import androidx.test.platform.app.InstrumentationRegistry
6+
import com.suwiki.core.database.database.TimetableDatabase
7+
import com.suwiki.core.database.database.migration.TIMETABLE_MIGRATION_1_2
8+
import com.suwiki.core.database.di.DatabaseName
9+
import org.junit.Rule
10+
import org.junit.Test
11+
import org.junit.runner.RunWith
12+
import java.io.IOException
13+
14+
@RunWith(AndroidJUnit4::class)
15+
class TimetableDatabaseMigrate1To2Test {
16+
17+
@get:Rule
18+
val helper: MigrationTestHelper = MigrationTestHelper(
19+
InstrumentationRegistry.getInstrumentation(),
20+
TimetableDatabase::class.java,
21+
)
22+
23+
@Test
24+
@Throws(IOException::class)
25+
fun testTimetableDBMigrate1To2() {
26+
var db = helper.createDatabase(DatabaseName.TIMETABLE, 1).apply {
27+
val testCellList = """
28+
[
29+
{"color":-9728172,"credit":"","day":"목","endTime":"4","location":"미래520","name":"도전과창조-기업가정신","professor":"김기선","startTime":"3"},
30+
{"color":-4026526,"credit":"","day":"화","endTime":"6","location":"미래520","name":"도전과창조-기업가정신","professor":"홍태민","startTime":"5"},
31+
{"color":-96120,"credit":"","day":"화","endTime":"1","location":"인문407","name":"언어와문화(이러닝)","professor":"김동섭","startTime":"1"},
32+
{"color":-96120,"credit":"","day":"토","endTime":"4","location":"인문407","name":"언어와문화(이러닝)","professor":"김동섭","startTime":"3"},
33+
{"color":-12363882,"credit":"","day":"","endTime":"","location":"이러닝","name":"도전과창조-기업가정신","professor":"김기선","startTime":""},
34+
{"color":-6194752,"credit":"","day":"토","endTime":"6","location":"미래520","name":"도전과창조-기업가정신","professor":"김기선","startTime":"5"}
35+
]
36+
""".trimIndent()
37+
38+
execSQL(
39+
"""
40+
INSERT INTO TimetableList (createTime, year, semester, timeTableName, timeTableJsonData)
41+
VALUES ('1706152141568', '2024', '1', '테스트 시간표 이름', '$testCellList')
42+
""".trimIndent(),
43+
)
44+
45+
close()
46+
}
47+
48+
db = helper.runMigrationsAndValidate(
49+
/* name = */ DatabaseName.TIMETABLE,
50+
/* version = */ 1,
51+
/* validateDroppedTables = */ true,
52+
/* ...migrations = */ TIMETABLE_MIGRATION_1_2,
53+
)
54+
}
55+
}

Diff for: gradle/libs.versions.toml

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[versions]
22
android-gradle-plugin = "8.1.2"
33
material = "1.10.0"
4-
junit4 = "4.13.2"
54
espresso = "3.4.0"
65
ksp = "1.9.10-1.0.13"
76
google-service = "4.3.15"
@@ -56,13 +55,16 @@ lottie = "6.0.0"
5655

5756
oss-plugin = "0.10.6"
5857
oss = "17.0.1"
59-
junit = "1.1.5"
60-
espresso-core = "3.5.1"
61-
androidx-test-ext-junit = "1.1.5"
58+
junit4 = "4.13.2"
59+
6260

6361
protobuf-plugin = "0.9.4"
6462
protobuf = "3.24.4"
6563

64+
espresso-core = "3.5.1"
65+
junit-ktx = "1.1.5"
66+
androidx-test-runner = "1.5.2"
67+
6668
[plugins]
6769
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
6870
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
@@ -177,13 +179,14 @@ lottie = { group = "com.airbnb.android", name = "lottie", version.ref = "lottie"
177179
room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "room" }
178180
room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "room" }
179181
room-runtime = { group = "androidx.room", name = "room-runtime", version.ref = "room" }
180-
181-
junit4 = { group = "junit", name = "junit", version.ref = "junit4" }
182+
room-testing = { group = "androidx.room", name = "room-testing", version.ref = "room" }
182183

183184
oss-licenses = { group = "com.google.android.gms", name = "play-services-oss-licenses", version.ref = "oss" }
184-
junit = { group = "androidx.test.ext", name = "junit-ktx", version.ref = "junit" }
185+
186+
junit4 = { group = "junit", name = "junit", version.ref = "junit4" }
187+
androidx-junit-ktx = { group = "androidx.test.ext", name = "junit-ktx", version.ref = "junit-ktx" }
188+
androidx-test-runner = { group = "androidx.test", name = "runner", version.ref = "androidx-test-runner" }
185189
espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espresso-core" }
186-
androidx-test-ext-junit = { group = "androidx.test.ext", name = "junit", version.ref = "androidx-test-ext-junit" }
187190

188191
protobuf-kotlin-lite = { group = "com.google.protobuf", name = "protobuf-kotlin-lite", version.ref = "protobuf" }
189192
protobuf-protoc = { group = "com.google.protobuf", name = "protoc", version.ref = "protobuf" }

Diff for: local/login/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ dependencies {
1616
implementation(libs.bundles.coroutine)
1717

1818
testImplementation(libs.junit4)
19-
androidTestImplementation(libs.junit)
19+
androidTestImplementation(libs.junit4)
2020
}

Diff for: local/openmajor/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ dependencies {
2525
implementation(libs.androidx.datastore.preferences)
2626

2727
testImplementation(libs.junit4)
28-
androidTestImplementation(libs.junit)
28+
androidTestImplementation(libs.junit4)
2929
}

Diff for: local/timetable/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ dependencies {
2626
implementation(libs.androidx.datastore.preferences)
2727

2828
testImplementation(libs.junit4)
29-
androidTestImplementation(libs.junit)
29+
androidTestImplementation(libs.junit4)
3030
}

Diff for: local/user/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ dependencies {
1919
implementation(libs.protobuf.kotlin.lite)
2020

2121
testImplementation(libs.junit4)
22-
androidTestImplementation(libs.junit)
22+
androidTestImplementation(libs.junit4)
2323
}

0 commit comments

Comments
 (0)