GoogleTest

A GoogleTest (GTest, also sometimes called "native tests") for the platform typically accesses lower-level HALs or performs raw IPC against various system services. Because of this, the testing approach is usually tightly coupled with the service under test.

To integrate with continuous testing infrastructure, build your GTests using the GTest framework.

Examples

Here are some examples of GTest in the platform source:

Summary of steps

  1. Follow the example GTest module setup.

  2. To automatically include GTest dependencies, use the BUILD_NATIVE_TEST build rule in your test module configuration.

  3. Write a test configuration, following the examples for simple and complex options.

  4. Build the test module with mmm for incremental builds, or mma for full builds:

    make hwui_unit_tests -j
    
  5. Run the test locally using Atest:

      atest hwui_unit_tests
    

    You can also add arguments to your GTests. The following are especially useful arguments:

    • native-test-flag specifies additional flag values to pass to the GTest shell command.
    • native-test-timeout specifies a test timeout value in microseconds.

      The following example code uses both of these arguments:

      atest test-name -- --module-arg test-name:native-test-flag:"\"argument1 argument2\"" \
         --module-arg test-name:native-test-timeout:60000
      
  6. Run the test with the Trade Federation test harness:

    make tradefed-all -j
    tradefed.sh run template/local_min --template:map test=hwui_unit_tests
    
  7. Manually install and run:

    1. Push the generated test binary onto your device:

       adb push ${OUT}/data/nativetest/hwui_unit_tests/hwui_unit_tests \
       /data/nativetest/hwui_unit_tests/hwui_unit_tests
      
    2. Launch GTest and execute the test by invoking the test binary on the device:

       adb shell /data/nativetest/hwui_unit_tests/hwui_unit_tests
      

      For more information about customizing test execution, add the --help parameter to your test binary. For more information on parameters, refer to the GTest advanced guide.