diff --git a/build-logic/convention/src/main/java/DataConventionPlugin.kt b/build-logic/convention/src/main/java/DataConventionPlugin.kt index 04b0d073d..691d41716 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 2e1478705..cdace5984 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 66102b845..ff39520f1 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 0e87ad9dd..41fdb77e5 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 5c51868b0..4af014bca 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 { @@ -36,6 +41,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) @@ -43,4 +49,7 @@ dependencies { implementation(libs.protobuf.kotlin.lite) implementation(libs.kotlinx.serialization.json) + + 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 1fd2132bf..000000000 --- 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 000000000..112e15f65 --- /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/gradle/libs.versions.toml b/gradle/libs.versions.toml index 62da6632d..10ceac567 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" @@ -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" } @@ -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" } diff --git a/local/login/build.gradle.kts b/local/login/build.gradle.kts index 02b7e06a9..eaf861ded 100644 --- a/local/login/build.gradle.kts +++ b/local/login/build.gradle.kts @@ -16,5 +16,5 @@ dependencies { implementation(libs.bundles.coroutine) testImplementation(libs.junit4) - androidTestImplementation(libs.junit) + androidTestImplementation(libs.junit4) } diff --git a/local/openmajor/build.gradle.kts b/local/openmajor/build.gradle.kts index f4edd8921..47c8681eb 100644 --- a/local/openmajor/build.gradle.kts +++ b/local/openmajor/build.gradle.kts @@ -25,5 +25,5 @@ dependencies { implementation(libs.androidx.datastore.preferences) testImplementation(libs.junit4) - androidTestImplementation(libs.junit) + androidTestImplementation(libs.junit4) } diff --git a/local/timetable/build.gradle.kts b/local/timetable/build.gradle.kts index 433bf2e7c..f93db7721 100644 --- a/local/timetable/build.gradle.kts +++ b/local/timetable/build.gradle.kts @@ -26,5 +26,5 @@ dependencies { implementation(libs.androidx.datastore.preferences) testImplementation(libs.junit4) - androidTestImplementation(libs.junit) + androidTestImplementation(libs.junit4) } diff --git a/local/user/build.gradle.kts b/local/user/build.gradle.kts index db54a5f18..c3e7f5e52 100644 --- a/local/user/build.gradle.kts +++ b/local/user/build.gradle.kts @@ -19,5 +19,5 @@ dependencies { implementation(libs.protobuf.kotlin.lite) testImplementation(libs.junit4) - androidTestImplementation(libs.junit) + androidTestImplementation(libs.junit4) }