{"id":987,"date":"2014-10-14T21:12:17","date_gmt":"2014-10-14T13:12:17","guid":{"rendered":"http:\/\/www.yeetrack.com\/?p=987"},"modified":"2014-10-14T21:12:17","modified_gmt":"2014-10-14T13:12:17","slug":"roboitum%e4%b8%ad%e5%8a%a0%e5%85%a5%e5%a4%b1%e8%b4%a5%e9%87%8d%e8%b7%91%e6%9c%ba%e5%88%b6","status":"publish","type":"post","link":"https:\/\/www.yeetrack.com\/?p=987","title":{"rendered":"Roboitum\u4e2d\u52a0\u5165\u5931\u8d25\u91cd\u8dd1\u673a\u5236"},"content":{"rendered":"<h1>Roboitum\u4e2d\u52a0\u5165\u5931\u8d25\u91cd\u8dd1\u673a\u5236<\/h1>\n<p>Robotium\u662f\u4e2a\u5f00\u6e90\u7684android\u529f\u80fd\u6d4b\u8bd5\u81ea\u52a8\u5316\u6846\u67b6\uff0c\u6bd4\u8f83\u6d41\u884c\u3002\u6211\u5e73\u65f6\u4f7f\u7528robotium+maven+spoon\uff0c\u8fd9\u6837\u7684\u7ec4\u5408\u505aandrod\u81ea\u52a8\u5316\u3002\u505a\u754c\u9762\u81ea\u52a8\u5316\uff0c\u5c24\u5176\u662f\u79fb\u52a8\u7aef\uff0ccase\u7ecf\u5e38\u5931\u8d25\uff0c\u7f51\u7edc\u95ee\u9898\u3001\u7b49\u5f85\u673a\u5236\u4e0d\u5408\u7406\u3001\u624b\u673a\u95ee\u9898\u7b49\u7b49\u3002\u4e00\u4e2acase\u5931\u8d25\u540e\uff0c\u518d\u6b21\u8fd0\u884c\u53ef\u80fd\u53c8\u6b63\u5e38\u4e86\uff0c\u8fd9\u79cd\u60c5\u51b5\u5f88\u591a\u3002\u5176\u5b9e\u6211\u4eec\u5728\u4f7f\u7528Robotium\u65f6\uff0c\u53ef\u4ee5\u624b\u52a8\u5b9e\u73b0case\u5931\u8d25\u540e\uff0c\u91cd\u8dd1\u51e0\u6b21\uff0c\u5982\u679c\u51e0\u6b21\u90fd\u5931\u8d25\u4e86\uff0c\u90a3\u4e48case\u624d\u5224\u5b9a\u4e3a\u5931\u8d25\u3002<!--more--><\/p>\n<h2>\u65b9\u6cd5<\/h2>\n<p>\u4f7f\u7528Robotium\u8981\u7ee7\u627fRobotium\u7684<code>ActivityInstrumentationTestCase2<\/code>\u8fd9\u4e2a\u62bd\u8c61\u7c7b\uff0c\u5e76\u4e14\u8981\u5b9e\u73b0\u5176\u4e2d\u7684<code>setup<\/code>\u3001<code>tearDown<\/code>\u65b9\u6cd5\u3002\u5176\u4e2d\u8fd8\u6709\u4e00\u4e2a\u65b9\u6cd5<code>runTest<\/code>\u5c31\u662f\u63a7\u5236\u6267\u884c\u6211\u4eec\u7684\u6d4b\u8bd5\u7528\u4f8b\u7684\uff0c\u6211\u4eec\u53ef\u4ee5\u91cd\u8f7d\u8fd9\u4e2a\u65b9\u6cd5\uff0c\u5b9e\u73b0case\u5931\u8d25\u540e\u91cd\u8dd1\u3002\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code>    @Override\n    protected void runTest() throws Throwable {\n        int retryTimes = 3;\n\n        while(retryTimes &gt; 0)\n        {\n            try{\n                Log.d(\"Robotium\", \"super\");\n                super.runTest();\n                break;\n            } catch (Throwable e)\n            {\n                if(retryTimes &gt; 1) {\n                    Log.d(\"Robotium\", \"fail\uff0c\u91cd\u8dd1--\"+retryTimes);\n                    retryTimes--;\n                    tearDown();\n                    setUp();\n                    continue;\n                }\n                else\n                    throw e;  \/\/\u8bb0\u5f97\u629b\u51fa\u5f02\u5e38\uff0c\u5426\u5219case\u6c38\u8fdc\u4e0d\u4f1a\u5931\u8d25\n            }\n        }\n    }\n<\/code><\/pre>\n<p>Over\uff0c\u5c31\u8fd9\u4e48\u7b80\u5355\u3002<\/p>\n<h2>Spoon\u622a\u56fe\u91cd\u590d<\/h2>\n<p>\u56e0\u4e3a\u6211\u4f7f\u7528spoon\u63d2\u4ef6\uff0c\u91cd\u8dd1\u4f1a\u5bfc\u81f4\u622a\u56fe\u91cd\u590d\u51fa\u73b0\u3002\u6211\u73b0\u5728\u65f6\u4fee\u6539\u4e0bSpoon-client\u7684\u6e90\u7801\u3002\u5728Spoon-client\u7684Spoon\u8fd9\u4e2afinal\u7c7b\u4e2d\uff0c\u6709\u622a\u56fe\u7684\u5b9e\u73b0\u65b9\u6cd5\u3002\u90e8\u5206\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code>    public static File screenshot(Activity activity, String tag)        {\n        if (!TAG_VALIDATION.matcher(tag).matches()) {\n        throw new IllegalArgumentException(\"Tag must match \" + TAG_VALIDATION.pattern() + \".\");\n        }\n        try {\n        File screenshotDirectory =      obtainScreenshotDirectory(activity);\n        String screenshotName = System.currentTimeMillis() +        NAME_SEPARATOR + tag + EXTENSION;\n        File screenshotFile = new File(screenshotDirectory,         screenshotName);\n        takeScreenshot(screenshotFile, activity);\n        Log.d(TAG, \"Captured screenshot '\" + tag + \"'.\");\n        return screenshotFile;\n        } catch (Exception e) {\n        throw new RuntimeException(\"Unable to capture screenshot.\", e);\n        }\n    }\n<\/code><\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\u4f5c\u8005\u4e3a\u4e86\u9632\u6b62\u622a\u56fe\u91cd\u590d\u4f7f\u7528\u4e86\u65f6\u95f4\u6233\u65b9\u6cd5<code>System.currentTimeMillis()<\/code>\uff0c\u8fd9\u91cc\u6211\u4eec\u5c31\u628a\u65f6\u95f4\u6233\u53bb\u6389\uff0c\u8ba9\u91cd\u590d\u7684\u622a\u56fe\u76f4\u63a5\u8986\u76d6\u3002<\/p>\n<p>\u4ee3\u7801\u6539\u5b8c\uff0c\u6253\u5230\u672c\u5730maven\u4ed3\u5e93\uff0c\u6216\u8005\u79c1\u670d\uff0c\u4f7f\u7528\u5373\u53ef\u3002<\/p>\n<p>\u9644\u4e0aandroid-spoon\u63d2\u4ef6\u5730\u5740:<a href=\"https:\/\/github.com\/square\/spoon\">https:\/\/github.com\/square\/spoon<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Roboitum\u4e2d\u52a0\u5165\u5931\u8d25\u91cd\u8dd1\u673a\u5236 Robotium\u662f\u4e2a\u5f00\u6e90\u7684android\u529f\u80fd\u6d4b\u8bd5\u81ea\u52a8\u5316\u6846\u67b6\uff0c\u6bd4\u8f83\u6d41\u884c\u3002\u6211\u5e73\u65f6\u4f7f\u7528robotium+maven+spoon\uff0c\u8fd9\u6837\u7684\u7ec4\u5408\u505aandrod\u81ea\u52a8\u5316\u3002\u505a\u754c\u9762\u81ea\u52a8&#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":[43,8,45,7,16,42],"class_list":["post-987","post","type-post","status-publish","format-standard","hentry","category-coding","tag-android","tag-java","tag-maven","tag-7","tag-16","tag-42"],"views":5534,"_links":{"self":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/987","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=987"}],"version-history":[{"count":1,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/987\/revisions"}],"predecessor-version":[{"id":988,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/987\/revisions\/988"}],"wp:attachment":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=987"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=987"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=987"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}