如何构建 Trade Federation 测试用例

How to build Trade Federation test cases

我能够编译和执行位于 /tools/tradefederation/core/tests 内的 Trade Federation 测试用例。但是我怎样才能执行位于我的项目中的测试用例呢?我的单元和仪器测试用例位于 /vendor/xyz/packages/apps/MyApp/test 文件夹内。如何在此文件夹中构建 Trade Federation 和 运行 我的测试用例?感谢您对此提供任何帮助。

由于无法从别人那里得到答案,所以我很少研究并设法自己解决了。我将我的项目 main 类 和 test 类 构建到一个单独的 jar 文件中,该文件引用了它的所有依赖项。然后我将它放在 out/host/linux-x86/tradefed 文件夹中,以便 tradefed 可以检测到我的测试。然后我在构建 tradefed 后从终端执行它们。 Android.mk 文件下方将生成 jar 文件并将其复制到 tradefed 文件夹,

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := optional

LOCAL_STATIC_JAVA_LIBRARIES := \
    android-support-v13 \
    android-support-v4 


LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_RESOURCE_DIR := $(addprefix $(LOCAL_PATH)/, res)

LOCAL_PACKAGE_NAME:= MyUTSampleApp
LOCAL_CERTIFICATE := platform
LOCAL_DEX_PREOPT := false


include $(BUILD_PACKAGE)
# To include test folder.
#include $(call all-makefiles-under,$(LOCAL_PATH))


include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-java-files-under, test)
LOCAL_MODULE := sample-tests
LOCAL_MODULE_TAGS := optional
LOCAL_STATIC_JAVA_LIBRARIES := mockito-host junit-host android-support-test MyUTSampleApp android_stubs_current
#LOCAL_JAVA_LIBRARIES := tradefed host-libprotobuf-java-full 


LOCAL_JAR_MANIFEST := MANIFEST.mf


include $(BUILD_HOST_JAVA_LIBRARY)


# makefile rules to copy jars to HOST_OUT/tradefed
# so tradefed.sh can automatically add to classpath
DEST_JAR := $(HOST_OUT)/tradefed/$(LOCAL_MODULE).jar
$(DEST_JAR): $(LOCAL_BUILT_MODULE)
      $(copy-file-to-new-target)
$(LOCAL_INSTALLED_MODULE) : $(DEST_JAR)

您可以使用另一个 shell 脚本文件来执行这样的测试用例,

TEST_CLASS="com.example.myutsampleapp.LocalManagerTest"

FORWARDED_ARGS=()
while [[ $# -gt 0 ]]; do
  next=""
  case ${next} in
  --class)
    TEST_CLASS=""
    shift
    ;;
  *)
    FORWARDED_ARGS+=("")
    ;;
  esac
  shift
done


/home/bsherif/workspace/source/tools/tradefederation/core/tradefed.sh run singleCommand host -n \
  --console-result-reporter:suppress-passed-tests \
  --class ${TEST_CLASS} ${FORWARDED_ARGS[*]}