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.
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.
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).
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With