ekito / koin-samples Goto Github PK
View Code? Open in Web Editor NEWKOIN - a concise and pragmatic dependency injection framework for Kotlin -- #Samples
License: Apache License 2.0
KOIN - a concise and pragmatic dependency injection framework for Kotlin -- #Samples
License: Apache License 2.0
what is this org.koin.dsl.module.applicationContext
and why can't I import it when I have all of the needed libs?
sorry, I'm just sick of writing tests
Hi, I try to create UI test with koin, fragment and viewModel (architecture component)
@RunWith(AndroidJUnit4::class)
class LoginFragmentTest{
@before
fun init() {
startKoin(hsApp + viewModel + api)
activityRule.activity.setFragment(testFragment)
EspressoTestUtil.disableProgressBarAnimations(activityRule)
}
@test
fun loading() {
testFragment.model.loginLoading.value = true
Espresso.onView(ViewMatchers.withId(R.id.login_button)).check(ViewAssertions.matches(ViewMatchers.isEnabled()))
}
}
@OpenForTesting
class LoginFragment : HSFragment() {
val TAG = javaClass.simpleName
val model: LoginViewModel by viewModel()
val modelConfig: ConfigViewModel by viewModel()
val router : Router by inject()
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
model.loginSuccess.observe(this, Observer { response ->
Log.d(TAG, response.toString())
context?.let {
router.homeActivity(it)
}
})
model.failure.nonNull().observe(this) { it?.let { showError(it) } }
model.loginLoading.nonNull().observe(this) { state -> loginButton.isEnabled = !state}
}
}
I recived this error
java.lang.IllegalStateException: Can't access ViewModels from detached fragment at android.support.v4.app.Fragment.getViewModelStore(Fragment.java:255) at android.arch.lifecycle.ViewModelStores.of(ViewModelStores.java:60) at org.koin.android.architecture.ext.LifecycleOwnerExtKt.getViewModelByClass(LifecycleOwnerExt.kt:177) at org.koin.android.architecture.ext.LifecycleOwnerExtKt$viewModelByClass$1.invoke(LifecycleOwnerExt.kt:87) at org.koin.android.architecture.ext.LifecycleOwnerExtKt$viewModelByClass$1.invoke(Unknown Source:0) at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74) at com.ooma.hm.ui.login.LoginFragment.getModel(Unknown Source:7) at com.ooma.hm.ui.login.LoginFragmentTest.loading(LoginFragmentTest.kt:74) at java.lang.reflect.Method.invoke(Native Method) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at android.support.test.internal.runner.junit4.statement.RunBefores.evaluate(RunBefores.java:80) at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:433) at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55) at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55) at org.junit.rules.RunRules.evaluate(RunRules.java:20) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runners.Suite.runChild(Suite.java:128) at org.junit.runners.Suite.runChild(Suite.java:27) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at org.junit.runner.JUnitCore.run(JUnitCore.java:115) at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:58) at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:375) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2145)
Maybe, Do you have any test with koin, fragment and viewModel
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.