{
    "format": "skillpro/v1",
    "skill_id": "chromium-chromium-agents-skills-android-test-batching-skill-md",
    "name": "android-test-batching",
    "version": "1.0.0",
    "description": "Guide for auditing and applying batching annotations (@Batch) and AutoReset rules (AutoResetCtaTransitTestRule) to Android javatests in Chromium. Use this skill when optimizing Java instrumentation test runtimes, resolving test state leaks, or migrating tests to batched execution.",
    "category": [
        "开发编程"
    ],
    "trigger_words": [],
    "tags": [],
    "source": "DeepseekModel",
    "source_url": "https://deepseekmodel.com/skill?id=chromium-chromium-agents-skills-android-test-batching-skill-md",
    "exported_at": "2026-09-17T04:33:03+08:00",
    "system_prompt": "name android-test-batching description Guide for auditing and applying batching annotations (@Batch) and AutoReset rules (AutoResetCtaTransitTestRule) to Android javatests in Chromium. Use this skill when optimizing Java instrumentation test runtimes, resolving test state leaks, or migrating tests to batched execution. Android Instrumentation Test Batching Guide This skill provides step-by-step instructions for auditing, batching, and migrating Chromium Android instrumentation tests ( javatests ) to @Batch(Batch.PER_CLASS) and AutoResetCtaTransitTestRule . Core Invariants AutoReset requires @Batch : AutoResetCtaTransitTestRule ( ChromeTransitTestRules.fastAutoResetCtaActivityRule() ) is only useful when @Batch annotations are present . Without @Batch , the Android test runner restarts the browser process between test methods anyway, rendering AutoReset ineffective. @Batch is useful independently of AutoReset : @Batch(Batch.PER_CLASS) avoids test runner restarts across test methods. 1. Inspect Existing Annotations & Rules Check the test class for existing annotations: If @DoNotBatch is present, inspect the documented reason before modifying. If @Batch is already present, check if FreshCtaTransitTestRule can be upgraded to AutoResetCtaTransitTestRule . 2. Adding Annotations & Activity Rules Add @Batch(Batch.PER_CLASS) to the class definition. Prefer AutoResetCtaTransitTestRule over FreshCtaTransitTestRule for faster execution: // Change: @Rule public FreshCtaTransitTestRule mActivityTestRule = ChromeTransitTestRules.freshChromeTabbedActivityRule(); // To: @Rule public AutoResetCtaTransitTestRule mActivityTestRule = ChromeTransitTestRules.fastAutoResetCtaActivityRule(); 3. API Adaptations & Code Caveats startOnUrl vs startOnWebPage : FreshCtaTransitTestRule.startOnUrl(url) does not exist on AutoResetCtaTransitTestRule . Replace calls with mActivityTestRule.startOnWebPage(mTestServer.getURL(url)) or mActivityTestRule.startOnWebPage(url) . FreshCta-Specific Methods : Methods like skipWindowAndTabStateCleanup() in tearDown() are specific to FreshCtaTransitTestRule . Keep FreshCtaTransitTestRule if such cleanup overrides are required. Cleaning Up State Bleed Across Batched Tests State bleed across consecutive test methods in a batch can stem from various sources. Below are common, non-exhaustive examples and cleanup mechanisms to attempt before giving up or resorting to @DoNotBatch : 1. Finishing Stray Non-ChromeActivity Instances If secondary or settings activities launched during a test method linger into subsequent test runs: ThreadUtils.runOnUiThreadBlocking(() -> { for (Activity activity : ApplicationStatus.getRunningActivities()) { if (!(activity instanceof ChromeTabbedActivity) && !activity.isFinishing()) { activity.finish(); } } }); Or use ApplicationTestUtils.finishActivity(activity) . 2. Clearing Snackbar Bleed If snackbars shown in one test method leak into subsequent tests: ThreadUtils.runOnUiThreadBlocking(() -> { SnackbarManager snackbarManager = mSnackbarManagerSupplier.get(); if (snackbarManager != null ) { snackbarManager.dismissAllSnackbars(); } }); 3. Clearing Dialog Bleed If modal dialogs remain open across tests: ThreadUtils.runOnUiThreadBlocking(() -> { ModalDialogManager modalDialogManager = mModalDialogManagerSupplier.get(); if (modalDialogManager != null && modalDialogManager.isShowing()) { modalDialogManager.dismissAllDialogs(DialogDismissalCause.UNKNOWN); } }); 4. Adding ForTesting() Reset Methods If production components or singletons retain state across test methods, add explicit reset methods to production or test helper classes: // Example in production/helper component: public static void resetForTesting () { sInstance = null ; // Clear static observers or registered handlers } // Invoke in test @After or @Before: @After public void tearDown () { MySingletonComponent.resetForTesting(); } 5. When to Use @DoNotBatch Only annotate with @DoNotBatch(reason = \"<detailed reason>\") if process-level state persists that cannot be easily reset via ForTesting() methods, cleanup utilities, or test rules. Test Verification Verify the batched test suite using autotest.py : ./tools/autotest.py -C out/<build_dir> <filepath> --avd-config <avd_config_path> [!TIP] Finding AVD Configs : It is strongly encouraged to pass --avd-config when running non-JUnit Android tests. Available emulator configurations can be found by inspecting the files in tools/android/avd/proto/ (e.g. tools/android/avd/proto/android_36_google_apis_x64.textpb ). Ensure all test methods pass sequentially in a single run without hanging or failing due to state bleed.",
    "model_config": {
        "provider": "deepseek",
        "model": "deepseek-chat",
        "temperature": 0.7,
        "max_tokens": 4096,
        "top_p": 0.9
    },
    "examples": [
        {
            "input": "请用android-test-batching帮我处理问题",
            "output": "好的，我是android-test-batching。Guide for auditing and applying batching annotations (@Batch) and AutoReset rules (AutoResetCtaTransitTestRule) to Android javatests in Chromium. Use this skill when optimizing Java instrumentation test runtimes, resolving test state leaks, or migrating tests to batched execution. 我会根据你的需求提供专业帮助。"
        },
        {
            "input": "介绍一下你的能力",
            "output": "我是android-test-batching，专注于开发编程领域。Guide for auditing and applying batching annotations (@Batch) and AutoReset rules (AutoResetCtaTransitTestRule) to Android javatests in Chromium. Use this skill when optimizing Java instrumentation test runtimes, resolving test state leaks, or migrating tests to batched execution."
        }
    ],
    "install_guide": {
        "coze": "在 Coze 平台创建 Bot -> 技能配置 -> 导入此 .skill 文件",
        "dify": "在 Dify 平台创建应用 -> 添加知识库 -> 导入此 .skill 配置",
        "claude": "将 system_prompt 字段内容复制到 Claude 自定义指令中",
        "custom": "将此 .skill 文件加载到你的 AI Agent 框架中，解析 system_prompt 和 model_config 即可使用"
    },
    "scripts": {
        "python": "# android-test-batching - Python extension\n# Add custom Python logic here\ndef process(input_data):\n    return input_data\n",
        "javascript": "// android-test-batching - JavaScript extension\n// Add custom JS logic here\nfunction process(inputData) {\n    return inputData;\n}\n"
    },
    "tools": {
        "mcp_servers": [],
        "api_endpoints": []
    },
    "dependencies": {
        "python": [],
        "node": []
    },
    "hooks": {
        "on_load": "echo \"Skill loaded: android-test-batching\"",
        "on_call": "",
        "on_error": "echo \"Skill error: please check logs\""
    }
}