This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@CustomTestApplication(BaseApplication::class) | |
interface HiltTestApplication |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@UninstallModules(AnalyticsModule::class) | |
@HiltAndroidTest | |
class SettingsActivityTest { | |
@BindValue @JvmField | |
val analyticsService: AnalyticsService = FakeAnalyticsService() | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@UninstallModules(AnalyticsModule::class) | |
@HiltAndroidTest | |
class SettingsActivityTest { | |
@Module | |
@InstallIn(SingletonComponent::class) | |
abstract class TestModule { | |
@Singleton | |
@Binds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module | |
@TestInstallIn( | |
components = [SingletonComponent::class], | |
replaces = [AnalyticsModule::class] | |
) | |
abstract class FakeAnalyticsModule { | |
@Singleton | |
@Binds | |
abstract fun bindAnalyticsService( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module | |
@InstallIn(SingletonComponent::class) | |
abstract class AnalyticsModule { | |
@Singleton | |
@Binds | |
abstract fun bindAnalyticsService( | |
analyticsServiceImpl: AnalyticsServiceImpl | |
): AnalyticsService | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@HiltAndroidTest | |
class SettingsActivityTest { | |
@get:Rule | |
var hiltRule = HiltAndroidRule(this) | |
@Inject | |
lateinit var analyticsAdapter: AnalyticsAdapter | |
@Before |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@HiltAndroidTest | |
@Config(application = HiltTestApplication::class) | |
class SettingsActivityTest { | |
@get:Rule | |
var hiltRule = HiltAndroidRule(this) | |
// Robolectric tests here. | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A custom runner to set up the instrumented application class for tests. | |
class CustomTestRunner : AndroidJUnitRunner() { | |
override fun newApplication(cl: ClassLoader?, name: String?, context: Context?): Application { | |
return super.newApplication(cl, HiltTestApplication::class.java.name, context) | |
} | |
} | |
//gradle file add the testInstrumentationRunner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@HiltAndroidTest | |
class SettingsActivityTest { | |
@get:Rule | |
var hiltRule = HiltAndroidRule(this) | |
// UI tests here. | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dependencies { | |
// For Robolectric tests. | |
testImplementation("com.google.dagger:hilt-android-testing:2.28-alpha") | |
// ...with Kotlin. | |
kaptTest("com.google.dagger:hilt-android-compiler:2.28-alpha") | |
// ...with Java. | |
testAnnotationProcessor("com.google.dagger:hilt-android-compiler:2.28-alpha") | |
// For instrumented tests. |
NewerOlder