Used to easily set up an MVVM Kotlin project including UI and unit testing using Android Architecture Components and Dagger 2. This is meant to be used more as a reference than a starter project. I will be adding more extensions, utility methods, and base classes as needed.
- Add activity to ActivityBuilderModule
- Mark the activity for injection in onCreate()
override fun onCreate(savedInstanceState: Bundle?) {
AndroidInjection.inject(this) // Always call before the super class
super.onCreate(savedInstanceState)
...
}
- Implement HasSupportFragmentInjector to inject fragments tied to this activity
- Add fragment to FragmentBuilderModule
- Implement Injectable
- Use the injected ViewModelFactory when creating a ViewModel
- For fragments the ViewModelFactory in injected in onActivityCreated()
- Test an activity by mocking any objects and methods in activityInjector(). This is very clunky and I'm sure there has to be a better way to do this!
- For fragments use the SingleFragmentActivity to test the fragment in isolation and mock objects and methods as usual
*For the most part, you will only use JUnit and Mockito unless you use LiveData in your view model