我尝试使用代码覆盖率运行android单元测试。我正在使用Android示例NotePad。
这些是我使用的命令:
cd <main project folder>
android update project --path .
android update test-project -m <full path to main project> -p <full path to main project>\tests
cd ./tests
ant emma debug install test
测试成功运行。但最终艾玛无法生成报告html文件。
在这里,您将获得ant emma debug install test的命令行输出
Buildfile: C:\Users\Benedikt\workspace_android\NotePad\tests\build.xml
emma:
-set-mode-check:
-set-debug-files:
-check-env:
[checkenv] Android SDK Tools Revision 22.6.2
[checkenv] Installed at C:\Android\android-sdk
-setup:
[echo] Project Name: NotesListTest
[gettype] Project Type: Test Application
-set-debug-mode:
-debug-obfuscation-check:
-pre-build:
-build-setup:
[getbuildtools] Using latest Build Tools: 19.0.3
[echo] Resolving Build Target for NotesListTest...
[gettarget] Project Target: Android 4.4.2
[gettarget] API level: 19
[echo] ----------
[echo] Creating output directories if needed...
[echo] ----------
[echo] Resolving Dependencies for NotesListTest...
[dependency] Library dependencies:
[dependency] No Libraries
[dependency]
[dependency] ------------------
[echo] ----------
[echo] Building Libraries with 'debug'...
[subant] No sub-builds to iterate on
[echo] ----------
[echo] Building tested project at C:\Users\Benedikt\workspace_android\NotePad with 'instrument'...
-set-mode-check:
-set-instrumented-mode:
-check-env:
[checkenv] Android SDK Tools Revision 22.6.2
[checkenv] Installed at C:\Android\android-sdk
-setup:
[echo] Project Name: NotesList
[gettype] Project Type: Application
-set-debug-mode:
-debug-obfuscation-check:
-pre-build:
-build-setup:
[getbuildtools] Using latest Build Tools: 19.0.3
[echo] Resolving Build Target for NotesList...
[gettarget] Project Target: Android 4.4.2
[gettarget] API level: 19
[echo] ----------
[echo] Creating output directories if needed...
[echo] ----------
[echo] Resolving Dependencies for NotesList...
[dependency] Library dependencies:
[dependency] No Libraries
[dependency]
[dependency] ------------------
[echo] ----------
[echo] Building Libraries with 'instrument'...
[subant] No sub-builds to iterate on
-code-gen:
[mergemanifest] Found Deleted Target File
[mergemanifest] Merging AndroidManifest files into one.
[mergemanifest] Manifest merger disabled. Using project manifest only.
[echo] Handling aidl files...
[aidl] No AIDL files to compile.
[echo] ----------
[echo] Handling RenderScript files...
[echo] ----------
[echo] Handling Resources...
[aapt] Found Deleted Target File
[aapt] Generating resource IDs...
[echo] ----------
[echo] Handling BuildConfig class...
[buildconfig] No need to generate new BuildConfig.
-pre-compile:
-compile:
[javac] Compiling 1 source file to C:\Users\Benedikt\workspace_android\NotePad\bin\classes
[echo] Instrumenting classes from C:\Users\Benedikt\workspace_android\NotePad\bin/classes...
-post-compile:
-obfuscate:
-dex:
[dex] input: C:\Users\Benedikt\workspace_android\NotePad\bin\classes
[dex] input: C:\Android\android-sdk\tools\lib\emma_device.jar
[dex] Using Pre-Dexed emma_device-e05f8994020e22cd9d939f07950bd18a.jar <- C:\Android\android-sdk\tools\lib\emma_device.jar
[dex] Found Deleted Target File
[dex] Converting compiled files and external libraries into C:\Users\Benedikt\workspace_android\NotePad\bin\classes.dex...
[dx] Merged dex A (17 defs/29,2KiB) with dex B (297 defs/326,8KiB). Result is 314 defs/427,2KiB. Took 0,2s
-crunch:
[crunch] Crunching PNG Files in source dir: C:\Users\Benedikt\workspace_android\NotePad\res
[crunch] To destination dir: C:\Users\Benedikt\workspace_android\NotePad\bin\res
[crunch] Crunched 0 PNG files to update cache
-package-resources:
[aapt] Found Deleted Target File
[aapt] Creating full resource package...
-package:
[apkbuilder] Found Deleted Target File
[apkbuilder] Creating NotesList-instrumented-unaligned.apk and signing it with a debug key...
-post-package:
-do-debug:
[zipalign] Running zip align on final apk...
[echo] Debug Package: C:\Users\Benedikt\workspace_android\NotePad\bin\NotesList-instrumented.apk
[propertyfile] Updating property file: C:\Users\Benedikt\workspace_android\NotePad\bin\build.prop
[propertyfile] Updating property file: C:\Users\Benedikt\workspace_android\NotePad\bin\build.prop
[propertyfile] Updating property file: C:\Users\Benedikt\workspace_android\NotePad\bin\build.prop
[propertyfile] Updating property file: C:\Users\Benedikt\workspace_android\NotePad\bin\build.prop
instrument:
[zipalign] Run cancelled: no changes to input file C:\Users\Benedikt\workspace_android\NotePad\bin\NotesList-instrumented-unaligned.apk
[echo] Instrumented Package: C:\Users\Benedikt\workspace_android\NotePad\bin\NotesList-instrumented.apk
[propertyfile] Updating property file: C:\Users\Benedikt\workspace_android\NotePad\bin\build.prop
[propertyfile] Updating property file: C:\Users\Benedikt\workspace_android\NotePad\bin\build.prop
[propertyfile] Updating property file: C:\Users\Benedikt\workspace_android\NotePad\bin\build.prop
[propertyfile] Updating property file: C:\Users\Benedikt\workspace_android\NotePad\bin\build.prop
[testedprojectclasspath] Resolved classpath:
[testedprojectclasspath] C:\Users\Benedikt\workspace_android\NotePad\bin\classes
-code-gen:
[mergemanifest] Found Deleted Target File
[mergemanifest] Merging AndroidManifest files into one.
[mergemanifest] Manifest merger disabled. Using project manifest only.
[echo] Handling aidl files...
[aidl] No AIDL files to compile.
[echo] ----------
[echo] Handling RenderScript files...
[echo] ----------
[echo] Handling Resources...
[aapt] Found new input file
[aapt] Generating resource IDs...
[echo] ----------
[echo] Handling BuildConfig class...
[buildconfig] No need to generate new BuildConfig.
-pre-compile:
-compile:
-post-compile:
-obfuscate:
-dex:
[dex] input: C:\Users\Benedikt\workspace_android\NotePad\tests\bin\classes
[dex] Found Deleted Target File
[dex] Converting compiled files and external libraries into C:\Users\Benedikt\workspace_android\NotePad\tests\bin\classes.dex...
-crunch:
[crunch] Crunching PNG Files in source dir: C:\Users\Benedikt\workspace_android\NotePad\tests\res
[crunch] To destination dir: C:\Users\Benedikt\workspace_android\NotePad\tests\bin\res
[crunch] Crunched 0 PNG files to update cache
-package-resources:
[aapt] Found Deleted Target File
[aapt] Creating full resource package...
-package:
[apkbuilder] Found Deleted Target File
[apkbuilder] Creating NotesListTest-debug-unaligned.apk and signing it with a debug key...
-post-package:
-do-debug:
[zipalign] Running zip align on final apk...
[echo] Debug Package: C:\Users\Benedikt\workspace_android\NotePad\tests\bin\NotesListTest-debug.apk
[propertyfile] Updating property file: C:\Users\Benedikt\workspace_android\NotePad\tests\bin\build.prop
[propertyfile] Updating property file: C:\Users\Benedikt\workspace_android\NotePad\tests\bin\build.prop
[propertyfile] Updating property file: C:\Users\Benedikt\workspace_android\NotePad\tests\bin\build.prop
[propertyfile] Updating property file: C:\Users\Benedikt\workspace_android\NotePad\tests\bin\build.prop
-post-build:
debug:
install:
[echo] Installing C:\Users\Benedikt\workspace_android\NotePad\tests\bin\NotesListTest-debug.apk onto default emulator or device...
[exec] pkg: /data/local/tmp/NotesListTest-debug.apk
[exec] Success
[exec] 494 KB/s (8101 bytes in 0.016s)
-set-mode-check:
-set-instrumented-mode:
install:
[echo] Installing C:\Users\Benedikt\workspace_android\NotePad\bin\NotesList-instrumented.apk onto default emulator or device...
[exec] pkg: /data/local/tmp/NotesList-instrumented.apk
[exec] Success
[exec] 629 KB/s (211536 bytes in 0.328s)
installi:
-check-env:
[checkenv] Android SDK Tools Revision 22.6.2
[checkenv] Installed at C:\Android\android-sdk
-setup:
[echo] Project Name: NotesListTest
[gettype] Project Type: Test Application
-test-project-check:
test:
[getlibpath] Library dependencies:
[getlibpath] No Libraries
[echo] Running tests...
[echo] Running tests ...
[exec]
[exec] com.example.android.notepad.NotePadActivityTest:.
[exec] com.example.android.notepad.NotePadProviderTest:..........
[exec] Test results for InstrumentationTestRunner=...........
[exec] Time: 2.338
[exec]
[exec] OK (11 tests)
[exec]
[exec]
[exec] Generated code coverage data to /data/data/com.example.android.notepad/coverage.ec
[echo] Setting permission to download the coverage file...
[exec] run-as: Package 'com.example.android.notepad' is unknown
[echo] Downloading coverage file into project directory...
[exec] failed to copy '/data/data/com.example.android.notepad/coverage.ec' to 'C:\Users\Benedikt\workspace_android\NotePad\tests\bin\coverage.ec': Permission denied
[echo] Extracting coverage report...
BUILD FAILED
C:\Android\android-sdk\tools\ant\build.xml:1313: [EMMA v2.0.5312] report: no valid input data files have been specified
Total time...
我想发布C:\ Android \ android-sdk \ tools \ ant \ build.xml但文件很长。但我想它总是一样的......
有什么想法吗?
答案 0 :(得分:0)
命令ant emma debug install test仅在root设备或模拟器上成功(否则权限被拒绝)。
有用的提示: