diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 11310bc..3c25ed2 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -6,12 +6,16 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 + - uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 with: - java-version: 1.8 - - uses: actions/cache@v1 + distribution: 'adopt' + java-version: 17 + cache: gradle + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + - uses: actions/cache@v4 with: path: ~/.gradle/caches key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 387813f..db61f39 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,24 +1,25 @@ plugins { id("com.android.application") kotlin("android") - kotlin("kapt") + id("com.google.devtools.ksp") version "1.9.22-1.0.17" apply false } android { - compileSdkVersion(29) + namespace = "net.pot8os.kotlintestsample" + compileSdk = 34 defaultConfig { applicationId = "net.pot8os.kotlintestsample" - minSdkVersion(23) - targetSdkVersion(29) + minSdk = 23 + targetSdk = 34 versionCode = 1 versionName = "1.0" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 } buildTypes { @@ -40,13 +41,14 @@ android { } kotlinOptions { - jvmTarget = "1.8" + jvmTarget = "17" } buildFeatures.dataBinding = true - - packagingOptions { - exclude("META-INF/proguard/androidx-annotations.pro") + packaging { + resources { + excludes += setOf("META-INF/proguard/androidx-annotations.pro") + } } testOptions { @@ -67,5 +69,5 @@ dependencies { repositories { google() - jcenter() + mavenCentral() } diff --git a/app/src/androidTest/kotlin/net/pot8os/kotlintestsample/InstrumentedCalculatorTest.kt b/app/src/androidTest/kotlin/net/pot8os/kotlintestsample/InstrumentedCalculatorTest.kt index 1230c18..62256b6 100644 --- a/app/src/androidTest/kotlin/net/pot8os/kotlintestsample/InstrumentedCalculatorTest.kt +++ b/app/src/androidTest/kotlin/net/pot8os/kotlintestsample/InstrumentedCalculatorTest.kt @@ -1,7 +1,7 @@ package net.pot8os.kotlintestsample import androidx.test.ext.junit.runners.AndroidJUnit4 -import net.pot8s.kotlintestsample.CalculatorSpec +import net.pot8os.kotlintestsample.CalculatorSpec import org.junit.runner.RunWith /** diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6b317da..7712933 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,20 +1,20 @@ - + - - - - - - - - - + + + + + + + + diff --git a/app/src/test/kotlin/net/pot8os/kotlintestsample/RobolectricCalculatorTest.kt b/app/src/test/kotlin/net/pot8os/kotlintestsample/RobolectricCalculatorTest.kt index 6eba2f2..069f629 100644 --- a/app/src/test/kotlin/net/pot8os/kotlintestsample/RobolectricCalculatorTest.kt +++ b/app/src/test/kotlin/net/pot8os/kotlintestsample/RobolectricCalculatorTest.kt @@ -2,7 +2,6 @@ package net.pot8os.kotlintestsample import android.os.Build import androidx.test.ext.junit.runners.AndroidJUnit4 -import net.pot8s.kotlintestsample.CalculatorSpec import org.junit.runner.RunWith import org.robolectric.annotation.Config @@ -11,6 +10,6 @@ import org.robolectric.annotation.Config */ @RunWith(AndroidJUnit4::class) @Config( - sdk = [Build.VERSION_CODES.P] + sdk = [Build.VERSION_CODES.UPSIDE_DOWN_CAKE] ) class RobolectricCalculatorTest : CalculatorSpec() diff --git a/app/src/testShared/kotlin/CalculatorSpec.kt b/app/src/testShared/kotlin/CalculatorSpec.kt new file mode 100644 index 0000000..82e38c3 --- /dev/null +++ b/app/src/testShared/kotlin/CalculatorSpec.kt @@ -0,0 +1,75 @@ +package net.pot8os.kotlintestsample + +import androidx.fragment.app.testing.launchFragmentInContainer +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.ViewActions.click +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.espresso.matcher.ViewMatchers.withText +import org.junit.Before +import org.junit.Test +import java.text.DecimalFormat + +/** + * @author So Nakamura, 2020-Feb-15 + */ +abstract class CalculatorSpec { + + @Before + fun setup() { + launchFragmentInContainer(themeResId = R.style.Theme_MyApp) + } + + @Test + fun testSum() { + onView(withId(R.id.button_1)).perform(click()) + onView(withId(R.id.button_2)).perform(click()) + onView(withId(R.id.button_3)).perform(click()) + onView(withId(R.id.button_sum)).perform(click()) + onView(withId(R.id.button_3)).perform(click()) + onView(withId(R.id.button_2)).perform(click()) + onView(withId(R.id.button_1)).perform(click()) + onView(withId(R.id.button_calc)).perform(click()) + onView(withId(R.id.field)).check(matches(withText("${123 + 321}"))) + } + + @Test + fun testSub() { + onView(withId(R.id.button_9)).perform(click()) + onView(withId(R.id.button_9)).perform(click()) + onView(withId(R.id.button_9)).perform(click()) + onView(withId(R.id.button_sub)).perform(click()) + onView(withId(R.id.button_3)).perform(click()) + onView(withId(R.id.button_3)).perform(click()) + onView(withId(R.id.button_3)).perform(click()) + onView(withId(R.id.button_calc)).perform(click()) + onView(withId(R.id.field)).check(matches(withText("${999 - 333}"))) + } + + @Test + fun testMul() { + onView(withId(R.id.button_1)).perform(click()) + onView(withId(R.id.button_0)).perform(click()) + onView(withId(R.id.button_0)).perform(click()) + onView(withId(R.id.button_mul)).perform(click()) + onView(withId(R.id.button_2)).perform(click()) + onView(withId(R.id.button_0)).perform(click()) + onView(withId(R.id.button_0)).perform(click()) + onView(withId(R.id.button_calc)).perform(click()) + val formatter = DecimalFormat("#,###") + onView(withId(R.id.field)).check(matches(withText(formatter.format(100 * 200)))) + } + + @Test + fun testDiv() { + onView(withId(R.id.button_3)).perform(click()) + onView(withId(R.id.button_3)).perform(click()) + onView(withId(R.id.button_3)).perform(click()) + onView(withId(R.id.button_div)).perform(click()) + onView(withId(R.id.button_1)).perform(click()) + onView(withId(R.id.button_0)).perform(click()) + onView(withId(R.id.button_0)).perform(click()) + onView(withId(R.id.button_calc)).perform(click()) + onView(withId(R.id.field)).check(matches(withText("${333 / 100.0}"))) + } +} diff --git a/app/src/testShared/kotlin/net.pot8s.kotlintestsample/CalculatorSpec.kt b/app/src/testShared/kotlin/net.pot8s.kotlintestsample/CalculatorSpec.kt deleted file mode 100644 index d983344..0000000 --- a/app/src/testShared/kotlin/net.pot8s.kotlintestsample/CalculatorSpec.kt +++ /dev/null @@ -1,77 +0,0 @@ -package net.pot8s.kotlintestsample - -import androidx.fragment.app.testing.launchFragmentInContainer -import androidx.test.espresso.Espresso.onView -import androidx.test.espresso.action.ViewActions.click -import androidx.test.espresso.assertion.ViewAssertions.matches -import androidx.test.espresso.matcher.ViewMatchers.withId -import androidx.test.espresso.matcher.ViewMatchers.withText -import net.pot8os.kotlintestsample.CalculatorFragment -import net.pot8os.kotlintestsample.R -import org.junit.Before -import org.junit.Test -import java.text.DecimalFormat - -/** - * @author So Nakamura, 2020-Feb-15 - */ -abstract class CalculatorSpec { - - @Before - fun setup() { - launchFragmentInContainer(themeResId = R.style.Theme_MyApp) - } - - @Test - fun testSum() { - onView(withId(R.id.button_1)).perform(click()) - onView(withId(R.id.button_2)).perform(click()) - onView(withId(R.id.button_3)).perform(click()) - onView(withId(R.id.button_sum)).perform(click()) - onView(withId(R.id.button_3)).perform(click()) - onView(withId(R.id.button_2)).perform(click()) - onView(withId(R.id.button_1)).perform(click()) - onView(withId(R.id.button_calc)).perform(click()) - onView(withId(R.id.field)).check(matches(withText("${123 + 321}"))) - } - - @Test - fun testSub() { - onView(withId(R.id.button_9)).perform(click()) - onView(withId(R.id.button_9)).perform(click()) - onView(withId(R.id.button_9)).perform(click()) - onView(withId(R.id.button_sub)).perform(click()) - onView(withId(R.id.button_3)).perform(click()) - onView(withId(R.id.button_3)).perform(click()) - onView(withId(R.id.button_3)).perform(click()) - onView(withId(R.id.button_calc)).perform(click()) - onView(withId(R.id.field)).check(matches(withText("${999 - 333}"))) - } - - @Test - fun testMul() { - onView(withId(R.id.button_1)).perform(click()) - onView(withId(R.id.button_0)).perform(click()) - onView(withId(R.id.button_0)).perform(click()) - onView(withId(R.id.button_mul)).perform(click()) - onView(withId(R.id.button_2)).perform(click()) - onView(withId(R.id.button_0)).perform(click()) - onView(withId(R.id.button_0)).perform(click()) - onView(withId(R.id.button_calc)).perform(click()) - val formatter = DecimalFormat("#,###") - onView(withId(R.id.field)).check(matches(withText(formatter.format(100 * 200)))) - } - - @Test - fun testDiv() { - onView(withId(R.id.button_3)).perform(click()) - onView(withId(R.id.button_3)).perform(click()) - onView(withId(R.id.button_3)).perform(click()) - onView(withId(R.id.button_div)).perform(click()) - onView(withId(R.id.button_1)).perform(click()) - onView(withId(R.id.button_0)).perform(click()) - onView(withId(R.id.button_0)).perform(click()) - onView(withId(R.id.button_calc)).perform(click()) - onView(withId(R.id.field)).check(matches(withText("${333 / 100.0}"))) - } -} diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 97b2764..5accc9b 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -5,11 +5,11 @@ plugins { allprojects { repositories { google() - jcenter() + mavenCentral() } } dependencies { - implementation("com.android.tools.build:gradle:4.0.0") - implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72") + implementation("com.android.tools.build:gradle:8.2.2") + implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.22") } diff --git a/buildSrc/src/main/java/Dependencies.kt b/buildSrc/src/main/java/Dependencies.kt index 62074c2..2e037fa 100644 --- a/buildSrc/src/main/java/Dependencies.kt +++ b/buildSrc/src/main/java/Dependencies.kt @@ -1,38 +1,40 @@ import org.gradle.kotlin.dsl.DependencyHandlerScope fun DependencyHandlerScope.kotlin() { - implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.72") + implementation("org.jetbrains.kotlin:kotlin-stdlib:1.9.22") } fun DependencyHandlerScope.fragment() { - val version = "1.2.5" + val version = "1.6.2" implementation("androidx.fragment:fragment-ktx:$version") debugImplementation("androidx.fragment:fragment-testing:$version") + androidTestImplementation("androidx.fragment:fragment-testing:1.6.0") } fun DependencyHandlerScope.compat() { - implementation("androidx.appcompat:appcompat:1.1.0") + implementation("androidx.appcompat:appcompat:1.6.1") } fun DependencyHandlerScope.layout() { - implementation("androidx.constraintlayout:constraintlayout:1.1.3") - implementation("com.google.android.material:material:1.1.0") + implementation("androidx.constraintlayout:constraintlayout:2.1.4") + implementation("com.google.android.material:material:1.11.0") } fun DependencyHandlerScope.viewmodel() { - implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0") + implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0") } fun DependencyHandlerScope.test() { // These dependencies are consumed in both unit tests and instrumented tests. - debugImplementation("androidx.test.espresso:espresso-core:3.2.0") - debugImplementation("androidx.test:runner:1.2.0") - debugImplementation("androidx.test:rules:1.2.0") - debugImplementation("androidx.test.ext:junit-ktx:1.1.1") + debugImplementation("androidx.test.espresso:espresso-core:3.5.1") + debugImplementation("androidx.test:runner:1.5.2") + debugImplementation("androidx.test:rules:1.5.0") + debugImplementation("androidx.test.ext:junit-ktx:1.1.5") // Regarding robolectric, only test target is sufficient. - testImplementation("org.robolectric:robolectric:4.3.1") + testImplementation("org.robolectric:robolectric:4.11.1") } private const val implementation = "implementation" private const val debugImplementation = "debugImplementation" private const val testImplementation = "testImplementation" +private const val androidTestImplementation = "androidTestImplementation" diff --git a/gradle.properties b/gradle.properties index 5e8aa8b..a3cd645 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,3 +14,6 @@ org.gradle.parallel=true org.gradle.caching=true android.useAndroidX=true +android.defaults.buildfeatures.buildconfig=true +android.nonTransitiveRClass=false +android.nonFinalResIds=false diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f9fd66e..d1f4080 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-all.zip