執行 android create test-project -p . -m . 報錯:
Error: No AndroidManifest.xml file found in the main project directory
create test-project 命令需要指定被測項目的路徑(-m 參數),該路徑下必須包含 AndroidManifest.xml 和 project.properties 文件。若僅有 APK 無源碼,無法直接創建標準測試項目。
# 正確語法
android create test-project \
-m /path/to/main/project \ # 被測項目路徑(含 AndroidManifest.xml)
-n TestProjectName \ # 測試項目名稱
-p /path/to/test/project # 測試項目生成路徑
標準測試項目依賴源碼編譯,若只有 APK:
apktool 反編譯 APK 獲取 AndroidManifest.xmlAndroidJUnitRunner + UIAutomator / Espresso 進行黑盒測試當前建議使用 Gradle + AndroidX Test:
// build.gradle (Module: app)
android {
defaultConfig {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
}
dependencies {
androidTestImplementation "androidx.test:runner:1.5.2"
androidTestImplementation "androidx.test.espresso:espresso-core:3.5.1"
// Robotium
androidTestImplementation "com.jayway.android.robotium:robotium-solo:5.6.3"
}
命令行創建測試項目需被測項目含完整源碼結構;純 APK 測試請遷移至現代 Instrumentation 測試框架。