I found that one test, in particular, fails on pre-KitKat devices. I believe this is due to a change in the embedded WebView used on older Android devices (but maybe this is wrong). In any case, back to my question: I would like an elegant way to control whether the test was launched depending on the version of Android that runs on the device.
I am currently using code that briefly closes the test and passes it if the runtime is earlier than KitKat. Here is the relevant code:
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { assertTrue("Skipping this test as the Android version is too low.", true); return; }
Since then, I tried to use two annotations in turn: @TargetApi and @RequiresApi for example.
@Test @RequiresApi(Build.VERSION_CODES.KITKAT) public void zimTest() { Log.v("kiwixTesting", "Running zimTest() on Android version: " + Build.VERSION.SDK_INT); ... }
In both cases, the test was run on my test devices (including Android 4.3, 4.3, 4.4 and newer). I can say because the test runner shows that the test was successfully launched, and the output of the following Log.v("kiwixTesting", "Running zimTest() on Android version: " + Build.VERSION.SDK_INT); log Log.v("kiwixTesting", "Running zimTest() on Android version: " + Build.VERSION.SDK_INT); appears in the magazine.
The full code is here and I am tracking the work here
Can anyone suggest a better approach than mine? Thanks.
source share