Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit testing on Android NDK

Tags:

How do you run unit tests on Android native code (native C/C++, not Java)? So far I've only found one similar question, and the answer says use junit with JNI, which I don't want to do (adding JNI calls seems unnecessarily complicated for unit testing, and is not really a unit test of the native code anyway).

Does CppUnit (also suggested there) really work on Android? Note that I want the tests to run natively on the device, not on the host development environment. This looks like an Android port, is it worth looking at?

An official Google test framework like googletest would be ideal, but that doesn't seem to work with the NDK.

like image 298
Indivara Avatar asked Aug 08 '13 13:08

Indivara


People also ask

What is Android unit testing?

Unit tests or small tests only verify a very small portion of the app, such as a method or class. End-to-end tests or big tests verify larger parts of the app at the same time, such as a whole screen or user flow. Medium tests are in between and check the integration between two or more units.

How do you run a unit test?

To run all the tests in a default group, choose the Run icon and then choose the group on the menu. Select the individual tests that you want to run, open the right-click menu for a selected test and then choose Run Selected Tests (or press Ctrl + R, T).

What is unit testing?

Unit testing is a software development process in which the smallest testable parts of an application, called units, are individually and independently scrutinized for proper operation. This testing methodology is done during the development process by the software developers and sometimes QA staff.


1 Answers

I use googletest through NDK I use a $(call import-module to bring in the main .so and then have a single file in the executable that looks like

int main(int argc, char *argv[]) { #if RUN_GTEST     INIT_GTESTS(&argc,(char**)argv);     RUN_ALL_GTESTS(); #endif } 

And then I build that with BUILD_EXECUTABLE, deploy it like:

find libs/ -type f -print -exec adb push {} /data/local/tmp \; 

and run it like

adb shell LD_LIBRARY_PATH=/data/local/tmp:/vendor/lib:/system/lib /data/local/tmp/gtest 

So it doesn't test the application life cycle but it tests all the unit tests.

If I needed to test something with a UI I could do something similar but make what's now 'main' a native function and invoke it when the activity is loaded.

like image 155
Doug-W Avatar answered Sep 24 '22 15:09

Doug-W