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 | |
class TestApplicationModule( | |
private val userRepository: UserRepository = FakeUserRepository(), | |
private val detailsRepository: DetailsRepository = FakeDetailsRepository()) { | |
@Provides | |
@Singleton | |
fun provideUserRepository(): UserRepository { | |
return userRepository | |
} |
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
@Before | |
fun setUp() { | |
MockitoAnnotations.initMocks(this) | |
TestInjector(TestApplicationModule(mockUserRepository)).inject() | |
} |
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
class TestInjector(private val testApplicationModule: TestApplicationModule) { | |
fun inject() { | |
val instrumentation = InstrumentationRegistry.getInstrumentation() | |
val app = instrumentation.targetContext.applicationContext as TestApplication | |
DaggerTestApplicationComponent | |
.builder() | |
.appModule(testApplicationModule) | |
.create(app) |
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
@RunWith(AndroidJUnit4::class) | |
class UserListFragmentTest { | |
@Rule | |
@JvmField | |
var activityRule = ActivityTestRule(MainActivity::class.java, true, false) | |
@Mock | |
private lateinit var mockUserRepository: UserRepository |
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
android { | |
compileSdkVersion 27 | |
buildToolsVersion "27.0.3" | |
defaultConfig { | |
applicationId "com.example.tamaskozmer.kotlinrxexample" | |
minSdkVersion 16 | |
targetSdkVersion 27 | |
versionCode 1 | |
versionName "1.0" | |
testInstrumentationRunner "com.example.tamaskozmer.kotlinrxexample.testutil.CustomTestRunner" |
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
class CustomTestRunner : AndroidJUnitRunner() { | |
override fun newApplication(cl: ClassLoader?, className: String?, context: Context?): Application { | |
return super.newApplication(cl, TestApplication::class.java.name, context) | |
} | |
} |
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
class TestApplication : Application(), HasSupportFragmentInjector { | |
@Inject | |
lateinit var fragmentInjector: DispatchingAndroidInjector<Fragment> | |
override fun supportFragmentInjector() = fragmentInjector | |
} |
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
class CustomApplication : DaggerApplication() { | |
override fun applicationInjector(): AndroidInjector<out DaggerApplication> { | |
return DaggerApplicationComponent.builder().create(this) | |
} | |
} |
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
@RunWith(AndroidJUnit4::class) | |
class UserListFragmentTest { | |
@Rule | |
@JvmField | |
var activityRule = ActivityTestRule(MainActivity::class.java, true, false) | |
@Mock | |
private lateinit var mockUserRepository: UserRepository |
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
class CustomApplication : Application() { | |
lateinit var component: ApplicationComponent | |
override fun onCreate() { | |
super.onCreate() | |
component = DaggerApplicationComponent | |
.builder() | |
.applicationModule(ApplicationModule(this)) |
NewerOlder