What is the purpose of @Rule in Android Espresso UI Test? -


new android unit testing espresso, under @rule, purpose of creating member variable? name of variable matter? inkling need tell test unit activity (or service, class) i'm testing, variable , scope used anywhere need care about?

    @rule     public activitytestrule<menuactivity> mactivitytestrule = new activitytestrule<>(menuactivity.class); 

after doing more practice , reserach android ui testing espresso, got many of use cases @rule variables. of of testing idling resources (view , data happen async). using activitytestrule object (ex. mactivitytestrule) can reference resources, fire public methods tag @visiblefortesting in class.

ex.

// in activity     @visiblefortesting     @nonnull     public simpleidlingresource getmsimpleidlingresource()     {         if (msimpleidlingresource == null)         {             msimpleidlingresource = new simpleidlingresource();         }         return msimpleidlingresource;     }  // in test class     // test run.     @before     public void registeridlingresource() {         midlingresource = mactivitytestrule.getactivity().getmsimpleidlingresource();     } 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -