Skip to content

Commit

Permalink
BDT-123, Composeのhiltのテストに失敗するがjavaを1.8にすれば解決するかもしれない
Browse files Browse the repository at this point in the history
  • Loading branch information
hondayuki0606 committed Mar 21, 2024
1 parent b2a1004 commit a67f9cb
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
19 changes: 13 additions & 6 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ android {
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
// testInstrumentationRunner = "com.example.babydiarycompose.CustomTestRunner"
// testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunner = "com.example.babydiarycompose.CustomTestRunner"
// Consult the README on instructions for setting up Unsplash API key
buildConfigField("String", "UNSPLASH_ACCESS_KEY", "\"" + getUnsplashAccess() + "\"")

Expand All @@ -36,14 +36,21 @@ android {
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
// compileOptions {
// sourceCompatibility = JavaVersion.VERSION_17
// targetCompatibility = JavaVersion.VERSION_17
// }
kotlin {
jvmToolchain(8)
}
hilt {
enableTransformForLocalTests = true
}
kotlinOptions {
jvmTarget = "17"
jvmTarget = "1.8"
}
buildFeatures {
viewBinding = true
Expand Down Expand Up @@ -75,7 +82,7 @@ dependencies {
// Hilt Navigation
implementation("androidx.hilt:hilt-navigation-compose:1.2.0")
// Use Dagger Hilt
implementation("com.google.dagger:hilt-android:2.48.1")
implementation("com.google.dagger:hilt-android:2.49")
ksp("com.google.dagger:hilt-android-compiler:2.48")
annotationProcessor("androidx.hilt:hilt-compiler:1.2.0")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.babydiarycompose

import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import org.junit.Before
import org.junit.Rule
import org.junit.Test

@HiltAndroidTest
class ComposeTest {
@get:Rule
var hiltRule = HiltAndroidRule(this)
@Before
fun init() {
hiltRule.inject()
}

@Test
fun test(){

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.babydiarycompose

import android.app.Application
import android.content.Context
import androidx.test.runner.AndroidJUnitRunner
import dagger.hilt.android.testing.HiltTestApplication

class CustomTestRunner : AndroidJUnitRunner() {

override fun newApplication(cl: ClassLoader?, name: String?, context: Context?): Application {
return super.newApplication(cl, HiltTestApplication::class.java.name, context)
}
}

0 comments on commit a67f9cb

Please sign in to comment.