Android_Java_API_tests

Alexander Alekhin edited this page Jun 16, 2016 · 2 revisions
Clone this wiki locally

Android Java API tests

This page is under construction!!!

http://opencv.willowgarage.com/wiki/OpenCV2.3.1JavaAPIcoverage

Running tests from Eclipse

  1. Open the Eclipse, create a new workspace and select a path to Android SDK: Eclipse Menu → Window → Preferences → Android → SDK Location.
  2. Import the OpenCV Java API project (OpenCV project):
    • Select Eclipse Menu → File → Import → General → Existing project into Workspace.
    • Select root directory — point Eclipse to your opencv_trunk/android/build (or opencv_trunk/android/build_armeabi folder)
    • Press Finish
  3. Import the OpenCV Java API Test project (Test project):
    • Select Eclipse Menu → File → Import → General → Existing project into Workspace
    • Select root directory — point Eclipse to your opencv_trunk/modules/java/android_test
    • Press Finish
  4. For Test project set the reference to OpenCV project: Project properties → Android → Library → Add and point to OpenCV project.
  5. Fix project properties: Eclipse Menu → Project → Build All, Eclipse Menu → Project → Clean, F5.
  6. Right click on Test project and choose Run as → Android JUnit Test.

Test project structure

  • Tests in repository: http://github.com/opencv/opencv/tree/master/modules/java/android_test
  • class OpenCVTestCase has/implements the all stuff needed for OpenCV testing
    • all the OpenCV test classes are subclasses of OpenCVTestCase
    • test_1 (candidate for termination) is for adb log formatting, it allows separate tests from different modules.
  • Each OpenCV module has a major test class with static methods: coreTest, imgprocTest, …
  • Some OpenCV classes also have their own test class: MatTest

If you want more details, just open the code in Eclipse. Its self-documented ;)

Running tests from the command line

  • If you have built OpenCV, you can find apk with tests in opencv_trunk/android/build/bin directory.
  • Working folder for test application on device /data/data/org.opencv.test/files.
  • How to work with tests from command line: http://developer.android.com/guide/developing/testing/testing_otheride.html.

    adb uninstall org.opencv.test
    adb install bin/opencv_test_java.apk
    adb shell am instrument -w org.opencv.test/.OpenCVTestRunner

Show all errors and failures except “Not yet implemented”

adb shell am instrument -w org.opencv.test/.OpenCVTestRunner | grep -E "junit.frameworklException" -A4 | sed -e '/Not yet implemented/,+5d'

To run modules independently

adb shell am instrument -w -e package org.opencv.test.core org.opencv.test/.OpenCVTestRunner
adb shell am instrument -w -e package org.opencv.test.imgproc org.opencv.test/.OpenCVTestRunner
...
adb shell am instrument -w -e package org.opencv.test.<MODULE_NAME> org.opencv.test/.OpenCVTestRunner

Running tests with run.py

Running the whole test package:


python run.py . -a -t java

Running tests for specific module:


python run.py . -a -t java —package .core

Some tips

  • JUnit window allows you to run a single test or tests from one test class (coreTest, imgprocTest). This is useful during the test development.
    • you can call them from JUnit view pane
    • from source code: right click on test method name
  • Ctrl + F11 will run opened test case
  • Linux tips
    • Calculate test coverage

      (cd android/build && python ../../modules/java/check-tests.py ./src ../../modules/java/android_test/src)
    • Build tests only

      make -j8 opencv_test_java_android_project
    • To get blacklist, run

      find -name “*.java” | xargs grep XXX