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 MvvmTestingApplication : DaggerApplication() { | |
override fun onCreate() { | |
super.onCreate() | |
Injector.init(this) | |
} | |
override fun applicationInjector(): AndroidInjector<out DaggerApplication> { | |
return DaggerAppComponent.builder().application(this).build() | |
} |
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 AndroidTestApplication : Application() |
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 AndroidTestRunner : AndroidJUnitRunner() { | |
override fun newApplication(cl: ClassLoader, className: String, context: Context): Application { | |
// The DexOpener library allows to make Kotlin classes, properties and functions | |
// open during tests in order to mock then with Mockito. | |
DexOpener.install(this) | |
return super.newApplication(cl, AndroidTestApplication::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
android { | |
... | |
defaultConfig { | |
... | |
testInstrumentationRunner "com.melnykov.mvvmtesting.testutil.AndroidTestRunner" | |
} | |
} |
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
@MediumTest | |
@RunWith(AndroidJUnit4::class) | |
class LoginFragmentTest { | |
@Rule | |
@JvmField | |
val activityRule = IntentsTestRule(SingleFragmentActivity::class.java) | |
@Rule | |
@JvmField |
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
@Test | |
fun emailAndPasswordAreEmptyInitially() { | |
onView(withId(R.id.edit_text_email)).check(matches(withText(""))) | |
onView(withId(R.id.edit_text_password)).check(matches(withText(""))) | |
} |
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
@Test | |
fun isSignInButtonEnabledBinding() { | |
isSignInButtonEnabled.set(true) | |
onView(withId(R.id.button_sign_in)).check(matches(isEnabled())) | |
} | |
@Test | |
fun isProgressBarVisibleBinding() { | |
isProgressBarVisible.set(true) | |
onView(withId(R.id.progress_overlay)).check(matches(isDisplayed())) |
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
@Test | |
fun clickForgotPasswordButton_CallsViewModel() { | |
onView(withId(R.id.label_forgot_password)).perform(click()) | |
verify(viewModel).onForgotPasswordLabelClicked() | |
verifyNoMoreInteractions(viewModel) | |
} | |
@Test | |
fun clickSignInButton_CallsViewModel() { |
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
@Test | |
fun navigateToForgotPasswordPage_StartsBrowser() { | |
intending(not(isInternal())).respondWith( | |
Instrumentation.ActivityResult(Activity.RESULT_OK, null)) | |
navigateToForgotPasswordPage.call() | |
intended(allOf(hasAction(Intent.ACTION_VIEW), | |
hasData(Urls.FORGOT_PASSWORD))) | |
} |
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 SingleFragmentActivity : AppCompatActivity() { | |
fun setFragment(fragment: Fragment) { | |
supportFragmentManager.beginTransaction() | |
.add(android.R.id.content, fragment) | |
.commit() | |
} | |
} |