0

I want to run an Espresso instrumentation test for my application. Test contains navigation to multiple activities and interactions with several widgets.

What could be the best possible coding style I should follow to keep code clear and maintainable.

For now I had create different class for each activity and access static test method as follow:

@Test
public void validateUserNavigationScenario() {
    // Create a bitmap we can use for our simulated camera image
    SignOnActivity.validateLogin();

    ProductSelector.selectProduct();

    ProductDetail.showProductDetails();

    ProductDetail.addProductToCart();

    pressBack();

    ProductSelector.selectProduct();

    // ... additional test steps and validation ...
}
Víctor Albertos
  • 8,093
  • 5
  • 43
  • 71
Krishnakant
  • 1,453
  • 3
  • 18
  • 30

1 Answers1

3

Coding test code is not different from coding production code.

The same good patterns and habits used for production code should be present in testing code. Using static reference as the main approach to structure all your suits seems to me a bad decision.

You should check it out Jake Wharton's talk about how to structure your testing code.

Instrumentation Testing Robots

It is focus on Kotlin development, but the same principles apply for Java. To sump up, it claims that you should hide your internal details inside some sort of “robot” pattern. Which means that you should try to be as much semantic as possible with your exposing API in order to create readable and maintainable tests.

Think on your test as if they were be used for other devs, and then think that you are one of them. How do you want it to use them?

Víctor Albertos
  • 8,093
  • 5
  • 43
  • 71
  • Can you help me with this question: http://stackoverflow.com/questions/38455085/espresso-select-item-from-adapter-view – Krishnakant Jul 19 '16 at 10:17