data class MavericksMock<V : MavericksView, Args : Parcelable>
Defines a unique variation of a View's state for testing purposes.
A view is represented completely by:
For proper mocking, the View MUST NOT reference data from any other sources, such as static singletons, dependency injection, shared preferences, etc. All of this should be channeled through the ViewModel and State. Otherwise a mock cannot deterministically and completely be used to test the View.
An exception is Android OS level View state, with things such as scroll and cursor positions. These are not feasible to track in state, and are generally independent and inconsequential in testing.
It is recommended that the "Default" mock state for a view represent the most canonical, complete form of the View. For example, all data loaded, with no empty or null instances.
Other mock variations should test alterations to this "default" state, with each variant testing a minimal difference (ideally only one change). For example, a variant may test that a single property is null or empty.
This pattern is encouraged because:
enum class Type
There are a set of standard mock variants that all Views have. Beyond that users can define custom mock variants. |
val args: Args?
Returns the arguments that should be used to initialize the Mavericks view. If null, the view models will be initialized purely with the mock states instead. |
|
val forInitialization: Boolean
If true, this mock tests the view being created either from arguments or with the viewmodels' default constructor (when args is null). |
|
val isDefaultInitialization: Boolean |
|
val isDefaultState: Boolean |
|
val isForProcessRecreation: Boolean |
|
val name: String |
|
val states: List<MockState<V, *>>
The State to set on each ViewModel in the View. There should be a one to one match. |
|
val type: MavericksMock.Type |
fun stateForViewModelProperty(property: KProperty<*>, existingViewModel: Boolean): MavericksState?
Find a mocked state value for the given view model property. |