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
private val fragmentViewModel: EmailLoginFragmentViewModel by viewModel() |
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 KoinTestApp: Application() { | |
override fun onCreate() { | |
super.onCreate() | |
startKoin { | |
androidLogger() | |
androidContext(this@KoinTestApp) | |
modules(emptyList()) | |
} | |
} | |
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 KoinTestRunner: AndroidJUnitRunner() { | |
override fun newApplication(cl: ClassLoader?, className: String?, context: Context?): Application { | |
return super.newApplication( | |
cl, KoinTestApp::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 "path.to.your.package.KoinTestRunner" | |
} | |
} |
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 { | |
testOptions { | |
animationsDisabled = true | |
} | |
} |
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
abstract class FragmentTestRule<F: Fragment>: ActivityTestRule<FragmentActivity>(FragmentActivity::class.java, true) { | |
override fun afterActivityLaunched() { | |
super.afterActivityLaunched() | |
activity.runOnUiThread { | |
val fm = activity.supportFragmentManager | |
val transaction = fm.beginTransaction() | |
transaction.replace( | |
android.R.id.content, | |
createFragment() | |
).commit() |
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
<?xml version="1.0" encoding="utf-8"?> | |
<manifest | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.github.olegosipenko.kointestsample"> | |
<application> | |
<activity | |
android:theme="@style/AppTheme" | |
android:name="androidx.fragment.app.FragmentActivity"/> | |
</application> | |
</manifest> |
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(AndroidJUnit4ClassRunner::class) | |
class EmailLoginFragmentTest { | |
private val fragmentViewModel: EmailLoginFragmentViewModel = mockk(relaxed = true) | |
private val fragment = EmailLoginFragment() | |
@get:Rule | |
val fragmentRule = createRule(fragment, module { | |
single(override = true) { | |
fragmentViewModel |
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
sealed class Expr | |
data class Const(val number: Double) : Expr() | |
data class Sum(val e1: Expr, val e2: Expr) : Expr() | |
object NotANumber : Expr() | |
fun eval(expr: Expr): Double = when(expr) { | |
is Const -> expr.number |
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
sealed class EmailLoginViewState { | |
object INITIAL: EmailLoginViewState() | |
object LOADING: EmailLoginViewState() | |
object SUCCESS: EmailLoginViewState() | |
... | |
} |
OlderNewer