我能够编译和执行位于/tools/tradefederation/core/tests
内的Trade Federation测试用例。但是,如何执行位于项目中的测试用例?我的单元和仪器测试用例位于/vendor/xyz/packages/apps/MyApp/test
文件夹中。如何在此文件夹中构建Trade Federation并运行我的测试用例?对此有任何帮助表示赞赏。
答案 0 :(得分:1)
由于我无法从别人那里得到答案,所以我做了很少的研究,并设法自己解决。我将我的项目主类和测试类构建到一个单独的jar文件中,该文件引用了所有依赖项。然后我将它放在out/host/linux-x86/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="$1"
case ${next} in
--class)
TEST_CLASS="$2"
shift
;;
*)
FORWARDED_ARGS+=("$1")
;;
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[*]}