{"id":570,"date":"2013-05-25T16:54:04","date_gmt":"2013-05-25T08:54:04","guid":{"rendered":"http:\/\/www.yeetrack.com\/?p=570"},"modified":"2013-09-27T22:36:39","modified_gmt":"2013-09-27T14:36:39","slug":"robotium%e9%97%ae%e7%ad%94","status":"publish","type":"post","link":"https:\/\/www.yeetrack.com\/?p=570","title":{"rendered":"Robotium\u95ee\u7b54"},"content":{"rendered":"<h4>\u5982\u4f55\u5f00\u59cb\uff1f<\/h4>\n<p>\u4e0b\u8f7d<a href=\"http:\/\/robotium.googlecode.com\/files\/robotium-solo-4.1.jar\" target=\"_blank\">Robotium.jar<\/a>\uff0c\u5c06\u5176\u52a0\u8f7d\u5230\u5de5\u7a0b\u7684build path\u4e2d\u3002\u66f4\u52a0\u8be6\u7ec6\u7684\u4ecb\u7ecd\uff0c\u70b9\u51fb<a href=\"http:\/\/code.google.com\/p\/robotium\/wiki\/Getting_Started\" target=\"_blank\">\u6b64\u5904<\/a>\u3002<\/p>\n<h4>Robotium\u652f\u6301\u4ec0\u4e48\u5b89\u5353\u4ec0\u4e48\u7248\u672c\uff1f<\/h4>\n<p>Robotium\u652f\u6301\u5b89\u53531.6\uff0c\u53ca\u4ee5\u4e0a<\/p>\n<h4>Robotium \u652f\u6301\u5728\u771f\u673a\u4e0a\u6d4b\u8bd5\u5417\uff1f<\/h4>\n<p>\u652f\u6301\u3002\u53ea\u8981\u5c06\u624b\u673a\u8fde\u63a5\u5230\u7535\u8111\uff0c\u5c31\u53ef\u4ee5\u50cf\u5728\u865a\u62df\u673a\u4e0a\u8fd0\u884c\u4e00\u6837\u3002\u5bf9\u4e8e\u4e00\u4e9b\u5b9a\u5236\u7684\u5b89\u5353\u7248\u672c\uff0c\u53ef\u80fd\u4f1a\u6709\u4e9b\u95ee\u9898\uff0c\u4f46\u662f\u591a\u6570\u60c5\u51b5\uff0c\u90fd\u53ef\u4ee5\u901a\u8fc7\u5c1d\u8bd5Robotium\u7684\u5176\u4ed6\u65b9\u6cd5\u89e3\u51b3\u3002<!--more--><\/p>\n<h4>Robotium\u652f\u6301\u90a3\u4e9b\u529f\u80fd\uff1f<\/h4>\n<p>\u53ef\u4ee5\u901a\u8fc7Robotium\u5728\u7ebf<a href=\"http:\/\/robotium.googlecode.com\/svn\/doc\/index.html\" target=\"_blank\">Javadoc<\/a>\uff0c\u6765\u67e5\u770bRobotium\u7684\u6240\u6709\u529f\u80fd\u3002\u4e5f\u53ef\u4ee5<a href=\"http:\/\/robotium.googlecode.com\/files\/robotium-solo-4.1-javadoc.jar\" target=\"_blank\">\u4e0b\u8f7d\u8fd9\u4e9b\u6587\u6863<\/a>\u3002\u8fd9\u4e9b\u5e2e\u52a9\u6587\u6863\u4ee5zip\u683c\u5f0f\u6253\u6210jar\u5305\u3002\u5982\u679c\u4e0d\u77e5\u9053\u600e\u4e48\u89e3\u538b\uff0c\u53ef\u4ee5\u5c06\u62d3\u5c55\u540d\u76f4\u63a5\u6539\u4e3azip\uff0c\u7136\u540e\u89e3\u538b\u3002<\/p>\n<h4>\u4f7f\u7528Robotium\u5199\u51fa\u7684case\uff0c\u53ef\u4ee5\u8de8\u5e94\u7528\u5417\uff1f<\/h4>\n<p>\u4e0d\u53ef\u4ee5\u3002\u5728\u6d4b\u8bd5\u5de5\u7a0b\u91cc\u7684AndroidManifest.xml\u6211\u4eec\u5df2\u7ecf\u58f0\u660e\u8981\u6d4b\u8bd5\u7684\u5e94\u7528\uff0c\u53ea\u80fd\u6d4b\u8bd5\u8fd9\u4e00\u4e2a\u5e94\u7528\u3002\u5982\u4f8b\u5b50\uff1a<code>&lt;instrumentation android:targetPackage=\"com.example.android.notepad\" android:name=\"android.test.InstrumentationTestRunner\" \/&gt;<\/code><br \/>\n\u4e0a\u9762\u7684\u4ee3\u7801\u8868\u660e\uff0c\u6211\u4eec\u8981\u6d4b\u8bd5<code>com.example.android.notepad<\/code>\u8fd9\u4e2a\u5305\u3002android\u4e0d\u5141\u8bb8\u6211\u4eec\u5bf9\u5176\u4e4b\u5916\u7684\u5e94\u7528\u8fdb\u884c\u64cd\u4f5c\u3002<\/p>\n<h4>\u5982\u679c\u53ea\u6709apk\u6587\u4ef6\uff0c\u80fd\u7528Robotium\u8fdb\u884c\u6d4b\u8bd5\u5417\uff1f<\/h4>\n<p>\u53ef\u4ee5\u3002\u4f7f\u7528Robotium\u4e0d\u9700\u8981android\u7a0b\u5e8f\u6e90\u7801\u3002\u66f4\u591a\u4fe1\u606f\u70b9\u51fb<a href=\"http:\/\/code.google.com\/p\/robotium\/wiki\/RobotiumForAPKFiles\" target=\"_blank\">\u6b64\u5904<\/a>\u3002<\/p>\n<h4>\u80fd\u4f7f\u7528Robotium\u6d4b\u8bd5\u624b\u673a\u4e2d\u9884\u88c5\u7684\u5e94\u7528\u5417\uff1f<\/h4>\n<p>\u53ef\u4ee5\uff0c\u4f46\u662f\u9700\u8981\u624b\u673a\u7684root\u6743\u9650\u3002\u8be6\u7ec6\u70b9\u51fb<a href=\"http:\/\/code.google.com\/p\/robotium\/wiki\/RobotiumForPreInstalledApps\" target=\"_blank\">\u6b64\u5904<\/a>\u3002<\/p>\n<h4>Robotium\u80fd\u6d4b\u8bd5\u6742\u5408\uff08web\u9875\u9762\uff09\u7684\u5e94\u7528\u5417\uff1f<\/h4>\n<p>\u53ef\u4ee5\u3002\u4eceRobotium 4.0\u5f00\u59cb\uff0c\u5c31\u652f\u6301\u542b\u6709web\u5185\u5bb9\u7684android\u5e94\u7528\u3002<\/p>\n<h4>\u80fd\u4f7f\u7528Robotium\u8fdb\u884c\u622a\u56fe\u5417\uff1f<\/h4>\n<p>\u53ef\u4ee5\u3002\u4f7f\u7528<code>takeScreenshot()<\/code>\u5c31\u53ef\u4ee5\u622a\u56fe\u624b\u673a\u5c4f\u5e55\uff0c\u4fdd\u5b58\u5230<code>\/sdcard\/Robotium-Screenshots\/<\/code>\u4e2d\u3002\u4f46\u662f\u9700\u8981\u6211\u4eec\u5728\u6d4b\u8bd5\u5de5\u7a0b\u7684AndroidManifest.xml\u6587\u4ef6\u4e2d\uff0c\u6253\u5f00\u5199\u6743\u9650<code>android.permission.WRITE_EXTERNAL_STORAGE<\/code>\u3002<\/p>\n<h4>\u5982\u4f55\u5728\u547d\u4ee4\u884c\u4e0b\u8fd0\u884cRobotium \u6d4b\u8bd5\u7528\u4f8b<\/h4>\n<p>\u4f7f\u7528\u4e0b\u9762\u7684\u547d\u4ee4\uff1a<br \/>\n<code>adb shell am instrument -w com.android.foo\/android.test.InstrumentationTestRunner<\/code><br \/>\n<code>com.android.foo<\/code>\u662f\u6211\u4eec\u6d4b\u8bd5\u5de5\u7a0b\u7684\u5305\u540d\u3002\u66f4\u591a\u4fe1\u606f\u70b9\u51fb<a href=\"http:\/\/developer.android.com\/reference\/android\/test\/InstrumentationTestRunner.html\" target=\"_blank\">\u6b64\u5904<\/a><\/p>\n<h4>\u5f53\u5bf9\u6587\u672c\u548c\u6309\u94ae\u8fdb\u884c\u70b9\u51fb\u64cd\u4f5c\u65f6\uff0c\u4e3a\u4ec0\u4e48\u4f1a\u62a5\u9519\uff1f<\/h4>\n<p>\u5982\u679c\u8fd9\u4e2a\u95ee\u9898\u53d1\u751f\u5728robotium\u652f\u6301\u7684android\u7248\u672c\u4e2d\uff0c\u53ef\u4ee5\u8bd5\u7740\u5728\u6d4b\u8bd5\u5de5\u7a0b\u7684AndroidManifest.xml\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4e0b\u9762\u914d\u7f6e\uff1a<br \/>\n<code>&lt;uses-sdk android:targetSdkVersion=\"YOUR_VERSION\" \/&gt;<\/code><br \/>\n\u5176\u4e2d\u7684<code>YOUR_VERSION<\/code>\uff1a6---&gt;android 2.0\u3001 7---&gt;android 2.1\u3001 8---&gt;android 2.2\uff0c\u6700\u65b0\u7684\u4e3a17---&gt;android 4.2\u3002<br \/>\n\u5982\u679c\u4e0a\u9762\u4ee3\u7801\u6709\u6ca1\u751f\u6548\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u5728\u6211\u4eec\u8981\u6d4b\u8bd5\u7684android\u5de5\u7a0b\u4e2d\u7684AndroidManifest.xml\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4e0b\u9762\u914d\u7f6e\uff1a<br \/>\n<code>&lt;supports-screens android:anyDensity=\"true\"\/&gt;<\/code><br \/>\n\u5982\u679c\u4e0a\u8ff0\u65b9\u6cd5\u5747\u65e0\u6548\uff0c\u53ef\u4ee5\u70b9\u51fb<a href=\"http:\/\/code.google.com\/p\/robotium\/issues\/list\" target=\"_blank\">\u6b64\u5904<\/a>\u53cd\u9988\u3002<\/p>\n<h4>\u53ef\u4ee5\u4f7f\u7528localised strings\u8fdb\u884c\u6d4b\u8bd5\u5417\uff1f<\/h4>\n<p>Yes you can. You can use\u00a0<code>solo.getString()<\/code>\u00a0and in there pass in the resource id of the string that you want to use. You will need to have the source code of the application under test to access the strings.<\/p>\n<h4>\u5982\u4f55\u7edf\u8ba1Robotium\u81ea\u52a8\u5316case\u7684\u8986\u76d6\u7387<\/h4>\n<p>\u76ee\u524d\uff0c\u9700\u8981\u4f7f\u7528ant\uff08\u6216\u8005\u4f7f\u7528\u547d\u4ee4\u884c\uff09\u3002<br \/>\n\u7531\u4e8e\u5b89\u5168\u9650\u5236\uff0c\u83b7\u53d6\u8986\u76d6\u7387\u53ea\u80fd\u5728\u6709root\u6743\u9650\u7684\u624b\u673a\u6216\u8005\u6a21\u62df\u5668\u4e0a\u8fdb\u884c\u3002<br \/>\n\u4e0b\u9762\u662f\u4e3b\u8981\u6b65\u9aa4\uff1a<\/p>\n<ul>\n<li>\u5728\u547d\u4ee4\u884c\u4e0b\u8fd0\u884c<code>android update test-project -m [\u76ee\u6807\u5e94\u7528\u8def\u5f84] -p [\u6d4b\u8bd5\u6587\u4ef6\u5939\u8def\u5f84]<\/code>,<code>android<\/code>\u8fd9\u4e2a\u547d\u4ee4\u662fandroid sdk\u4e0b\u7684android.bat\uff0c\u8fd0\u884c\u8fd9\u6761\u547d\u4ee4\u540e\uff0c\u5728\u6d4b\u8bd5\u6587\u4ef6\u5939\u4e2d\u4f1a\u751f\u6210\u4e00\u4e2abuild.xml\u6587\u4ef6\u3002<\/li>\n<li>\u786e\u4fddRobotium jar\u5305\u5728\u4f60\u7684\u6d4b\u8bd5\u5de5\u7a0b\u76ee\u5f55\u4e0b\uff0c\u4e00\u822c\u5728\u5de5\u7a0b\u76ee\u5f55\u4e0b\u7684libs\u6587\u4ef6\u5939\u4e2d\u3002<\/li>\n<li>ant\u9700\u8981\u83b7\u53d6\u5230\u76ee\u6807\u5e94\u7528\u7684class\u6587\u4ef6\u548c\u4f9d\u8d56\u7684jar\u5305\uff08\u524d\u63d0\u662f\u4f60\u6709\u76ee\u6807\u5e94\u7528\u7684\u6e90\u7801\uff0c\u5e76\u4e14\u53ef\u4ee5\u8fdb\u884cbuild\uff09\u3002\u53c2\u89c1<a href=\"http:\/\/stackoverflow.com\/questions\/2472059\/cant-build-and-run-an-android-test-project-created-using-ant-create-test-projec\" target=\"_blank\">http:\/\/stackoverflow.com\/questions\/2472059\/cant-build-and-run-an-android-test-project-created-using-ant-create-test-projec<\/a>,\u4e0b\u9762\u662f\u6211\u7684build.xml\u6587\u4ef6\u3002<\/li>\n<li>\u8fd0\u884c<code>ant coverage<\/code><\/li>\n<li>\u5982\u679c\u8fd0\u884c\u6210\u529f\uff0cant\u4f1a\u751f\u6210\u4e00\u4e2acoverage\u6587\u4ef6\u5939\uff0c\u91cc\u9762\u542b\u6709coverage.html\u6587\u4ef6\uff0c\u7528\u6d4f\u89c8\u5668\u6253\u5f00\u5373\u53ef\u67e5\u770b\u8986\u76d6\u7387 \ud83d\ude42<br \/>\n\u4e0b\u9762\u662f\u6211\u7684build.xml\u6587\u4ef6\u3002<\/p>\n<pre><code>&lt;!-- override \"compile\" target in platform android_rules.xml to include tested app's external libraries --&gt;  \n&lt;target name=\"compile\" depends=\"-resource-src, -aidl\"\n    description=\"Compiles project's .java files into .class files\"&gt;\n&lt;!-- If android rules are used for a test project, its classpath should include\n tested project's location --&gt;\n&lt;condition property=\"extensible.classpath\"\n               value=\"${tested.project.dir}\/bin\/classes\" else=\".\"&gt;\n&lt;isset property=\"tested.project.dir\" \/&gt;\n&lt;\/condition&gt;\n&lt;javac encoding=\"ascii\" target=\"1.5\" debug=\"true\" extdirs=\"\"\n    destdir=\"${out.classes.absolute.dir}\"\n    bootclasspathref=\"android.target.classpath\"\n    verbose=\"${verbose}\" classpath=\"${extensible.classpath}\"&gt;\n    &lt;src path=\"${source.absolute.dir}\" \/&gt;\n    &lt;src path=\"${gen.absolute.dir}\" \/&gt;\n    &lt;classpath&gt;\n        &lt;fileset dir=\"${tested.project.dir}\/libs\" includes=\"*.jar\" \/&gt;\n        &lt;fileset dir=\"${tested.project.dir}\/bin\/classes\" includes=\"*.class\" \/&gt;\n        &lt;fileset dir=\"${external.libs.absolute.dir}\/libs\" includes=\"*.jar\" \/&gt;\n    &lt;\/classpath&gt;\n&lt;\/javac&gt;\n&lt;\/target&gt;  \n<\/code><\/pre>\n<p>\u53ef\u4ee5copy\u4e0a\u9762\u7684\u914d\u7f6e\u5230\u4f60\u7684build.xml\u6587\u4ef6\u4e2d\u3002\u53e6\u5916\u5efa\u8bae\uff0c\u7f16\u8f91\u6d4b\u8bd5\u5de5\u7a0b\u3001\u76ee\u6807\u5de5\u7a0b\u6839\u76ee\u5f55\u4e0b\u7684<code>build.properties<\/code>\u8fd9\u4e2a\u6587\u4ef6\uff08\u5982\u679c\u6ca1\u6709\u5c31\u65b0\u5efa\uff09\uff0c\u5728\u91cc\u9762\u6dfb\u52a0<code>emma.enabled=true<\/code>\u3002<\/li>\n<\/ul>\n<p>\u82f1\u6587\u539f\u6587<a href=\"http:\/\/code.google.com\/p\/robotium\/wiki\/QuestionsAndAnswers\" target=\"_blank\">http:\/\/code.google.com\/p\/robotium\/wiki\/QuestionsAndAnswers<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5f00\u59cb\uff1f \u4e0b\u8f7dRobotium.jar\uff0c\u5c06\u5176\u52a0\u8f7d\u5230\u5de5\u7a0b\u7684build path\u4e2d\u3002\u66f4\u52a0\u8be6\u7ec6\u7684\u4ecb\u7ecd\uff0c\u70b9\u51fb\u6b64\u5904\u3002 Robotium\u652f\u6301\u4ec0\u4e48\u5b89\u5353\u4ec0\u4e48\u7248\u672c\uff1f Robotium\u652f\u6301\u5b89\u53531.6\uff0c\u53ca\u4ee5\u4e0a Robot&#46;&#46;&#46;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"pgc_sgb_lightbox_settings":"","footnotes":""},"categories":[33],"tags":[8,7,16,42,41],"class_list":["post-570","post","type-post","status-publish","format-standard","hentry","category-coding","tag-java","tag-7","tag-16","tag-42","tag-41"],"views":3476,"_links":{"self":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/570","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=570"}],"version-history":[{"count":2,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/570\/revisions"}],"predecessor-version":[{"id":572,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/570\/revisions\/572"}],"wp:attachment":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=570"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=570"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=570"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}