docs/testing/android_gtests.md
gtests are googletest-based C++ tests. On Android, they run on a device. In most cases, they're packaged as APKs, but there are a few cases where they're run as raw executables. The latter is necessary in a few cases, particularly when manipulating signal handlers, but isn't possible when the suite needs to call back through the JNI into Java code.
[TOC]
Gtest APKs are built by default by the test template, e.g.
test("sample_gtest") {
# ...
}
This uses gn's native shared_library target type along with the unittest_apk template to build an APK containing:
<instrumentation> and <activity> elements (among others).GTest APKs are packaged with a harness that consists of:
main function.am instrument with a bunch of arguments,
includes several extras that are arguments to either
NativeTestInstrumentationTestRunner or NativeTest. This results in an
intent being sent to NativeTestInstrumentationTestRunner.Gtest executables are built by passing
use_raw_android_executable = True to the
test
template, e.g.
test("sample_gtest_executable") {
if (is_android) {
use_raw_android_executable = true
}
# ...
}
This uses gn's native
executable
target type, then copies the resulting executable and any requisite shared libraries
to ${root_out_dir}/${target_name}__dist (e.g. out/Debug/breakpad_unittests__dist).
Unlike APKs, gtest suites built as executables require no Android-specific harnesses.
The test runner simply executes the binary on the device directly and parses the stdout on its own.