在Android NDK单元测试 [英] Unit testing on Android NDK
问题描述
你怎么跑在Android原生code单元测试(原生C / C ++,的不的Java的)?到目前为止,我只找到 之一类似的问题,得到的答复说,使用JUnit与JNI,这是我不想做(添加JNI调用似乎单元测试过于复杂,而不是真正的原生code的单元测试反正)。
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).
请问CppUnit的(也有人在那里)在Android真的管用吗?请注意,我想要检测设备上本地运行,而不是在主机开发环境。 这看起来像一个Android端口,它是值得看的?
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?
如 googletest 一个谷歌官方的测试框架将是理想的,但似乎不工作与NDK。
An official Google test framework like googletest would be ideal, but that doesn't seem to work with the NDK.
推荐答案
我用googletest通过NDK我使用$(调用导入模块主。所以把再有,看起来像可执行单个文件
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
}
然后我构建与BUILD_EXECUTABLE,部署这样的:
And then I build that with BUILD_EXECUTABLE, deploy it like:
find libs/ -type f -print -exec adb push {} /data/local/tmp \;
和像
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.
如果我需要一个UI我可以做类似的事情,但是做什么现在'主'原生功能,并调用它加载活动时来测试一些东西。
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.
这篇关于在Android NDK单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!