Skip to content

Commit

Permalink
Merge pull request #120 from uswLectureEvaluation/feature/#89-timetab…
Browse files Browse the repository at this point in the history
…le-migration-test

Feature/#89 시간표 데이터베이스 마이그레이션 테스트 코드 작성
  • Loading branch information
jinukeu authored Jan 25, 2024
2 parents 71a4837 + 6b9361f commit 4d58a84
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal class DataConventionPlugin : Plugin<Project> {

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

"androidTestImplementation"(libs.findLibrary("junit").get())
"androidTestImplementation"(libs.findLibrary("junit4").get())
"implementation"(libs.findLibrary("timber").get())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal class FeatureComposeConventionPlugin : Plugin<Project> {
"implementation"(libs.findLibrary("kotlinx.coroutines.android").get())
"implementation"(libs.findLibrary("kotlinx.coroutines.core").get())

"androidTestImplementation"(libs.findLibrary("junit").get())
"androidTestImplementation"(libs.findLibrary("junit4").get())
"implementation"(libs.findLibrary("timber").get())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal class RemoteConventionPlugin : Plugin<Project> {

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

"androidTestImplementation"(libs.findLibrary("junit").get())
"androidTestImplementation"(libs.findLibrary("junit4").get())
"implementation"(libs.findLibrary("timber").get())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal fun Project.configureKotlinAndroid(
defaultConfig {
minSdk = Const.minSdk

testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}

Expand Down
9 changes: 9 additions & 0 deletions core/database/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ ksp {

android {
namespace = "com.suwiki.core.database"

sourceSets {
// Adds exported schema location as test app assets.
getByName("androidTest").assets.srcDir("$rootDir/schemas")
}
}

protobuf {
Expand All @@ -36,11 +41,15 @@ dependencies {
ksp(libs.room.compiler)
implementation(libs.room.runtime)
implementation(libs.room.ktx)
androidTestImplementation(libs.room.testing)

implementation(libs.bundles.coroutine)
implementation(libs.androidx.datastore.core)
implementation(libs.androidx.datastore.preferences)
implementation(libs.protobuf.kotlin.lite)

implementation(libs.kotlinx.serialization.json)

androidTestImplementation(libs.androidx.junit.ktx)
androidTestImplementation(libs.androidx.test.runner)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.suwiki.database

import androidx.room.testing.MigrationTestHelper
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import com.suwiki.core.database.database.TimetableDatabase
import com.suwiki.core.database.database.migration.TIMETABLE_MIGRATION_1_2
import com.suwiki.core.database.di.DatabaseName
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import java.io.IOException

@RunWith(AndroidJUnit4::class)
class TimetableDatabaseMigrate1To2Test {

@get:Rule
val helper: MigrationTestHelper = MigrationTestHelper(
InstrumentationRegistry.getInstrumentation(),
TimetableDatabase::class.java,
)

@Test
@Throws(IOException::class)
fun testTimetableDBMigrate1To2() {
var db = helper.createDatabase(DatabaseName.TIMETABLE, 1).apply {
val testCellList = """
[
{"color":-9728172,"credit":"","day":"목","endTime":"4","location":"미래520","name":"도전과창조-기업가정신","professor":"김기선","startTime":"3"},
{"color":-4026526,"credit":"","day":"화","endTime":"6","location":"미래520","name":"도전과창조-기업가정신","professor":"홍태민","startTime":"5"},
{"color":-96120,"credit":"","day":"화","endTime":"1","location":"인문407","name":"언어와문화(이러닝)","professor":"김동섭","startTime":"1"},
{"color":-96120,"credit":"","day":"토","endTime":"4","location":"인문407","name":"언어와문화(이러닝)","professor":"김동섭","startTime":"3"},
{"color":-12363882,"credit":"","day":"","endTime":"","location":"이러닝","name":"도전과창조-기업가정신","professor":"김기선","startTime":""},
{"color":-6194752,"credit":"","day":"토","endTime":"6","location":"미래520","name":"도전과창조-기업가정신","professor":"김기선","startTime":"5"}
]
""".trimIndent()

execSQL(
"""
INSERT INTO TimetableList (createTime, year, semester, timeTableName, timeTableJsonData)
VALUES ('1706152141568', '2024', '1', '테스트 시간표 이름', '$testCellList')
""".trimIndent(),
)

close()
}

db = helper.runMigrationsAndValidate(
/* name = */ DatabaseName.TIMETABLE,
/* version = */ 1,
/* validateDroppedTables = */ true,
/* ...migrations = */ TIMETABLE_MIGRATION_1_2,
)
}
}
19 changes: 11 additions & 8 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[versions]
android-gradle-plugin = "8.1.2"
material = "1.10.0"
junit4 = "4.13.2"
espresso = "3.4.0"
ksp = "1.9.10-1.0.13"
google-service = "4.3.15"
Expand Down Expand Up @@ -56,13 +55,16 @@ lottie = "6.0.0"

oss-plugin = "0.10.6"
oss = "17.0.1"
junit = "1.1.5"
espresso-core = "3.5.1"
androidx-test-ext-junit = "1.1.5"
junit4 = "4.13.2"


protobuf-plugin = "0.9.4"
protobuf = "3.24.4"

espresso-core = "3.5.1"
junit-ktx = "1.1.5"
androidx-test-runner = "1.5.2"

[plugins]
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
Expand Down Expand Up @@ -177,13 +179,14 @@ lottie = { group = "com.airbnb.android", name = "lottie", version.ref = "lottie"
room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "room" }
room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "room" }
room-runtime = { group = "androidx.room", name = "room-runtime", version.ref = "room" }

junit4 = { group = "junit", name = "junit", version.ref = "junit4" }
room-testing = { group = "androidx.room", name = "room-testing", version.ref = "room" }

oss-licenses = { group = "com.google.android.gms", name = "play-services-oss-licenses", version.ref = "oss" }
junit = { group = "androidx.test.ext", name = "junit-ktx", version.ref = "junit" }

junit4 = { group = "junit", name = "junit", version.ref = "junit4" }
androidx-junit-ktx = { group = "androidx.test.ext", name = "junit-ktx", version.ref = "junit-ktx" }
androidx-test-runner = { group = "androidx.test", name = "runner", version.ref = "androidx-test-runner" }
espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espresso-core" }
androidx-test-ext-junit = { group = "androidx.test.ext", name = "junit", version.ref = "androidx-test-ext-junit" }

protobuf-kotlin-lite = { group = "com.google.protobuf", name = "protobuf-kotlin-lite", version.ref = "protobuf" }
protobuf-protoc = { group = "com.google.protobuf", name = "protoc", version.ref = "protobuf" }
Expand Down
2 changes: 1 addition & 1 deletion local/login/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ dependencies {
implementation(libs.bundles.coroutine)

testImplementation(libs.junit4)
androidTestImplementation(libs.junit)
androidTestImplementation(libs.junit4)
}
2 changes: 1 addition & 1 deletion local/openmajor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ dependencies {
implementation(libs.androidx.datastore.preferences)

testImplementation(libs.junit4)
androidTestImplementation(libs.junit)
androidTestImplementation(libs.junit4)
}
2 changes: 1 addition & 1 deletion local/timetable/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ dependencies {
implementation(libs.androidx.datastore.preferences)

testImplementation(libs.junit4)
androidTestImplementation(libs.junit)
androidTestImplementation(libs.junit4)
}
2 changes: 1 addition & 1 deletion local/user/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ dependencies {
implementation(libs.protobuf.kotlin.lite)

testImplementation(libs.junit4)
androidTestImplementation(libs.junit)
androidTestImplementation(libs.junit4)
}

0 comments on commit 4d58a84

Please sign in to comment.