From 030691e1398c6b2b76a1deefd5df459088bf8721 Mon Sep 17 00:00:00 2001 From: jinukeu Date: Thu, 25 Jan 2024 00:50:49 +0900 Subject: [PATCH 1/3] =?UTF-8?q?chore:=20room-test=20=EB=94=94=ED=8E=9C?= =?UTF-8?q?=EB=8D=98=EC=8B=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/database/build.gradle.kts | 1 + gradle/libs.versions.toml | 1 + 2 files changed, 2 insertions(+) diff --git a/core/database/build.gradle.kts b/core/database/build.gradle.kts index 5c51868b..a24155f8 100644 --- a/core/database/build.gradle.kts +++ b/core/database/build.gradle.kts @@ -36,6 +36,7 @@ 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) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 62da6632..e0798cb8 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -177,6 +177,7 @@ 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" } +room-testing = { group = "androidx.room", name = "room-testing", version.ref = "room" } junit4 = { group = "junit", name = "junit", version.ref = "junit4" } From e4ab89ae2e4e992e8c1ad25c9a0fef667a614a29 Mon Sep 17 00:00:00 2001 From: jinukeu Date: Thu, 25 Jan 2024 01:07:59 +0900 Subject: [PATCH 2/3] =?UTF-8?q?chore:=20junit=20version=20catalog=20?= =?UTF-8?q?=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/database/build.gradle.kts | 3 +++ core/network/build.gradle.kts | 2 +- core/security/build.gradle.kts | 4 ++-- gradle/libs.versions.toml | 6 +----- local/login/build.gradle.kts | 2 +- local/openmajor/build.gradle.kts | 2 +- local/timetable/build.gradle.kts | 2 +- local/user/build.gradle.kts | 2 +- 8 files changed, 11 insertions(+), 12 deletions(-) diff --git a/core/database/build.gradle.kts b/core/database/build.gradle.kts index a24155f8..46ff598a 100644 --- a/core/database/build.gradle.kts +++ b/core/database/build.gradle.kts @@ -44,4 +44,7 @@ dependencies { implementation(libs.protobuf.kotlin.lite) implementation(libs.kotlinx.serialization.json) + + testImplementation(libs.junit) + androidTestImplementation(libs.junit) } diff --git a/core/network/build.gradle.kts b/core/network/build.gradle.kts index 1ffa6706..6816d54a 100644 --- a/core/network/build.gradle.kts +++ b/core/network/build.gradle.kts @@ -30,7 +30,7 @@ dependencies { implementation(libs.retrofit.core) implementation(libs.retrofit.kotlin.serialization) implementation(libs.okhttp.logging) - androidTestImplementation(libs.junit4) + androidTestImplementation(libs.junit) implementation(libs.timber) } diff --git a/core/security/build.gradle.kts b/core/security/build.gradle.kts index cbe7bb13..ea6b1e4f 100644 --- a/core/security/build.gradle.kts +++ b/core/security/build.gradle.kts @@ -24,6 +24,6 @@ dependencies { implementation(libs.timber) - testImplementation(libs.junit4) - androidTestImplementation(libs.junit4) + testImplementation(libs.junit) + androidTestImplementation(libs.junit) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e0798cb8..c19ab286 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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" @@ -58,7 +57,6 @@ 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" protobuf-plugin = "0.9.4" protobuf = "3.24.4" @@ -179,12 +177,10 @@ room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "room" } room-runtime = { group = "androidx.room", name = "room-runtime", version.ref = "room" } room-testing = { group = "androidx.room", name = "room-testing", version.ref = "room" } -junit4 = { group = "junit", name = "junit", version.ref = "junit4" } - 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" } 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" } diff --git a/local/login/build.gradle.kts b/local/login/build.gradle.kts index 02b7e06a..4ed9a79b 100644 --- a/local/login/build.gradle.kts +++ b/local/login/build.gradle.kts @@ -15,6 +15,6 @@ dependencies { implementation(libs.bundles.coroutine) - testImplementation(libs.junit4) + testImplementation(libs.junit) androidTestImplementation(libs.junit) } diff --git a/local/openmajor/build.gradle.kts b/local/openmajor/build.gradle.kts index f4edd892..38d80d58 100644 --- a/local/openmajor/build.gradle.kts +++ b/local/openmajor/build.gradle.kts @@ -24,6 +24,6 @@ dependencies { implementation(libs.androidx.datastore.core) implementation(libs.androidx.datastore.preferences) - testImplementation(libs.junit4) + testImplementation(libs.junit) androidTestImplementation(libs.junit) } diff --git a/local/timetable/build.gradle.kts b/local/timetable/build.gradle.kts index 433bf2e7..0e715c5b 100644 --- a/local/timetable/build.gradle.kts +++ b/local/timetable/build.gradle.kts @@ -25,6 +25,6 @@ dependencies { implementation(libs.androidx.datastore.core) implementation(libs.androidx.datastore.preferences) - testImplementation(libs.junit4) + testImplementation(libs.junit) androidTestImplementation(libs.junit) } diff --git a/local/user/build.gradle.kts b/local/user/build.gradle.kts index db54a5f1..945fc480 100644 --- a/local/user/build.gradle.kts +++ b/local/user/build.gradle.kts @@ -18,6 +18,6 @@ dependencies { implementation(libs.androidx.datastore.preferences) implementation(libs.protobuf.kotlin.lite) - testImplementation(libs.junit4) + testImplementation(libs.junit) androidTestImplementation(libs.junit) } From 6b9361f0f895d6dfba3299ee5e0e09fdad3c5f14 Mon Sep 17 00:00:00 2001 From: jinukeu Date: Thu, 25 Jan 2024 12:34:42 +0900 Subject: [PATCH 3/3] =?UTF-8?q?test:=20=EC=8B=9C=EA=B0=84=ED=91=9C=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=EB=B2=A0=EC=9D=B4=EC=8A=A4=20?= =?UTF-8?q?=EB=A7=88=EC=9D=B4=EA=B7=B8=EB=A0=88=EC=9D=B4=EC=85=98=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/DataConventionPlugin.kt | 2 +- .../java/FeatureComposeConventionPlugin.kt | 2 +- .../src/main/java/RemoteConventionPlugin.kt | 2 +- .../com/kunize/convention/KotlinAndroid.kt | 2 +- core/database/build.gradle.kts | 9 ++- .../database/ExampleInstrumentedTest.kt | 22 -------- .../TimetableDatabaseMigrate1To2Test.kt | 55 +++++++++++++++++++ core/network/build.gradle.kts | 2 +- core/security/build.gradle.kts | 4 +- gradle/libs.versions.toml | 12 +++- local/login/build.gradle.kts | 4 +- local/openmajor/build.gradle.kts | 4 +- local/timetable/build.gradle.kts | 4 +- local/user/build.gradle.kts | 4 +- 14 files changed, 86 insertions(+), 42 deletions(-) delete mode 100644 core/database/src/androidTest/java/com/suwiki/database/ExampleInstrumentedTest.kt create mode 100644 core/database/src/androidTest/java/com/suwiki/database/TimetableDatabaseMigrate1To2Test.kt diff --git a/build-logic/convention/src/main/java/DataConventionPlugin.kt b/build-logic/convention/src/main/java/DataConventionPlugin.kt index 04b0d073..691d4171 100644 --- a/build-logic/convention/src/main/java/DataConventionPlugin.kt +++ b/build-logic/convention/src/main/java/DataConventionPlugin.kt @@ -18,7 +18,7 @@ internal class DataConventionPlugin : Plugin { "implementation"(libs.findBundle("coroutine").get()) - "androidTestImplementation"(libs.findLibrary("junit").get()) + "androidTestImplementation"(libs.findLibrary("junit4").get()) "implementation"(libs.findLibrary("timber").get()) } } diff --git a/build-logic/convention/src/main/java/FeatureComposeConventionPlugin.kt b/build-logic/convention/src/main/java/FeatureComposeConventionPlugin.kt index 2e147870..cdace598 100644 --- a/build-logic/convention/src/main/java/FeatureComposeConventionPlugin.kt +++ b/build-logic/convention/src/main/java/FeatureComposeConventionPlugin.kt @@ -26,7 +26,7 @@ internal class FeatureComposeConventionPlugin : Plugin { "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()) } } diff --git a/build-logic/convention/src/main/java/RemoteConventionPlugin.kt b/build-logic/convention/src/main/java/RemoteConventionPlugin.kt index 66102b84..ff39520f 100644 --- a/build-logic/convention/src/main/java/RemoteConventionPlugin.kt +++ b/build-logic/convention/src/main/java/RemoteConventionPlugin.kt @@ -19,7 +19,7 @@ internal class RemoteConventionPlugin : Plugin { "implementation"(libs.findBundle("coroutine").get()) - "androidTestImplementation"(libs.findLibrary("junit").get()) + "androidTestImplementation"(libs.findLibrary("junit4").get()) "implementation"(libs.findLibrary("timber").get()) } } diff --git a/build-logic/convention/src/main/java/com/kunize/convention/KotlinAndroid.kt b/build-logic/convention/src/main/java/com/kunize/convention/KotlinAndroid.kt index 0e87ad9d..41fdb77e 100644 --- a/build-logic/convention/src/main/java/com/kunize/convention/KotlinAndroid.kt +++ b/build-logic/convention/src/main/java/com/kunize/convention/KotlinAndroid.kt @@ -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 } diff --git a/core/database/build.gradle.kts b/core/database/build.gradle.kts index 46ff598a..4af014bc 100644 --- a/core/database/build.gradle.kts +++ b/core/database/build.gradle.kts @@ -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 { @@ -45,6 +50,6 @@ dependencies { implementation(libs.kotlinx.serialization.json) - testImplementation(libs.junit) - androidTestImplementation(libs.junit) + androidTestImplementation(libs.androidx.junit.ktx) + androidTestImplementation(libs.androidx.test.runner) } diff --git a/core/database/src/androidTest/java/com/suwiki/database/ExampleInstrumentedTest.kt b/core/database/src/androidTest/java/com/suwiki/database/ExampleInstrumentedTest.kt deleted file mode 100644 index 1fd2132b..00000000 --- a/core/database/src/androidTest/java/com/suwiki/database/ExampleInstrumentedTest.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.suwiki.database - -import androidx.test.ext.junit.runners.AndroidJUnit4 -import androidx.test.platform.app.InstrumentationRegistry -import junit.framework.TestCase.assertEquals -import org.junit.Test -import org.junit.runner.RunWith - -/** - * Instrumented test, which will execute on an Android device. - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -@RunWith(AndroidJUnit4::class) -class ExampleInstrumentedTest { - @Test - fun useAppContext() { - // Context of the app under test. - val appContext = InstrumentationRegistry.getInstrumentation().targetContext - assertEquals("com.suwiki.database.test", appContext.packageName) - } -} diff --git a/core/database/src/androidTest/java/com/suwiki/database/TimetableDatabaseMigrate1To2Test.kt b/core/database/src/androidTest/java/com/suwiki/database/TimetableDatabaseMigrate1To2Test.kt new file mode 100644 index 00000000..112e15f6 --- /dev/null +++ b/core/database/src/androidTest/java/com/suwiki/database/TimetableDatabaseMigrate1To2Test.kt @@ -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, + ) + } +} diff --git a/core/network/build.gradle.kts b/core/network/build.gradle.kts index 6816d54a..1ffa6706 100644 --- a/core/network/build.gradle.kts +++ b/core/network/build.gradle.kts @@ -30,7 +30,7 @@ dependencies { implementation(libs.retrofit.core) implementation(libs.retrofit.kotlin.serialization) implementation(libs.okhttp.logging) - androidTestImplementation(libs.junit) + androidTestImplementation(libs.junit4) implementation(libs.timber) } diff --git a/core/security/build.gradle.kts b/core/security/build.gradle.kts index ea6b1e4f..cbe7bb13 100644 --- a/core/security/build.gradle.kts +++ b/core/security/build.gradle.kts @@ -24,6 +24,6 @@ dependencies { implementation(libs.timber) - testImplementation(libs.junit) - androidTestImplementation(libs.junit) + testImplementation(libs.junit4) + androidTestImplementation(libs.junit4) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c19ab286..10ceac56 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -55,12 +55,16 @@ lottie = "6.0.0" oss-plugin = "0.10.6" oss = "17.0.1" -junit = "1.1.5" -espresso-core = "3.5.1" +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" } @@ -179,7 +183,9 @@ room-testing = { group = "androidx.room", name = "room-testing", version.ref = " 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" } protobuf-kotlin-lite = { group = "com.google.protobuf", name = "protobuf-kotlin-lite", version.ref = "protobuf" } diff --git a/local/login/build.gradle.kts b/local/login/build.gradle.kts index 4ed9a79b..eaf861de 100644 --- a/local/login/build.gradle.kts +++ b/local/login/build.gradle.kts @@ -15,6 +15,6 @@ dependencies { implementation(libs.bundles.coroutine) - testImplementation(libs.junit) - androidTestImplementation(libs.junit) + testImplementation(libs.junit4) + androidTestImplementation(libs.junit4) } diff --git a/local/openmajor/build.gradle.kts b/local/openmajor/build.gradle.kts index 38d80d58..47c8681e 100644 --- a/local/openmajor/build.gradle.kts +++ b/local/openmajor/build.gradle.kts @@ -24,6 +24,6 @@ dependencies { implementation(libs.androidx.datastore.core) implementation(libs.androidx.datastore.preferences) - testImplementation(libs.junit) - androidTestImplementation(libs.junit) + testImplementation(libs.junit4) + androidTestImplementation(libs.junit4) } diff --git a/local/timetable/build.gradle.kts b/local/timetable/build.gradle.kts index 0e715c5b..f93db772 100644 --- a/local/timetable/build.gradle.kts +++ b/local/timetable/build.gradle.kts @@ -25,6 +25,6 @@ dependencies { implementation(libs.androidx.datastore.core) implementation(libs.androidx.datastore.preferences) - testImplementation(libs.junit) - androidTestImplementation(libs.junit) + testImplementation(libs.junit4) + androidTestImplementation(libs.junit4) } diff --git a/local/user/build.gradle.kts b/local/user/build.gradle.kts index 945fc480..c3e7f5e5 100644 --- a/local/user/build.gradle.kts +++ b/local/user/build.gradle.kts @@ -18,6 +18,6 @@ dependencies { implementation(libs.androidx.datastore.preferences) implementation(libs.protobuf.kotlin.lite) - testImplementation(libs.junit) - androidTestImplementation(libs.junit) + testImplementation(libs.junit4) + androidTestImplementation(libs.junit4) }