Package 

Class MavericksMock


  • 
    public final class MavericksMock<V extends MavericksView, Args extends Parcelable>
    
                        

    Defines a unique variation of a View's state for testing purposes.

    A view is represented completely by:

    • The arguments used to initialize it

    • The State classes of all ViewModels used by the View

    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:

    • The tools for defining mock variations are designed to enable easy modification of the default

    • Each mock variant is only one line of code, and is easily maintained

    • Each variant tests a single edge case