Test guide - forem/ForemWebView-android Wiki

Overview

At Forem, we have following tests suites:

  • Robolectric testing
  • JUnit testing
  • Espresso / Ui Automator testing

Most of our test cases are written in Espresso + Ui Automator. This is normally not the preferred way but we have following reasons to do so:

  • our library/app heavily rely on website and therefore testing WebView is really important which can be done efficiently and easily in Espresso (as compared to Robolectric) using Espresso-Web.
  • a lot of our features work in native android outside the scope of our library like notifications, audio-notification and its play controls, picture-in-picture mode, etc. To test these features the best way is to use Ui Automator.

We do use robolectric to test some specific logically files which can be tested independently of WebView.

Naming Convention

Test names should read like a sentence, and be consistent with other nearby test names to facilitate easily coming up with new tests. Consider using a format similar to the following for naming test functions:

testAction_withOneCondition_withSecondCondition_hasExpectedOutcome

where testAction, withCondition and hasExpectedOutcome are replaced with appropriate descriptions in camelCase. Put the outcome at the end of the name, so that you and others can easily compare consecutive tests of the same method that have slightly different conditions with divergent outcomes.

For Example: testMainActivity_forwardImageView_isDisabledByDefault

Testing private methods/functions

Tests should only be written to verify the behaviour of public methods/functions. Private functions should not be used in behavioural tests.

ForemWebView-android project organization for tests

The following is the default directory structure for ForemWebView-android application and test code:

  • the entire app module is actually used for testing purposes only. It mainly uses the webview-library only.
  • app/src/test/java- for any unit test which can run on the JVM
  • app/src/androidTest/java- for any test which should run on an Android device