Przejdź do treści
Biblioteka skilli
Programowanie · Testowanie

android-test-batching

/android-test-batching

Audytuje i stosuje adnotacje wsadowe i reguły AutoReset do testów Java w Chromium, przy optymalizacji czasu instrumentacji i wycieków stanu testów.

Repozytorium
chromium ↗
Licencja
BSD-3-Clause
Ostatnia zmiana repozytorium
25.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
2
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 25.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

BSD-3-Clause, otwarta.

Co robi i kiedy

Audytuje i stosuje adnotacje wsadowe i reguły AutoReset do testów Java w Chromium, przy optymalizacji czasu instrumentacji i wycieków stanu testów.

Oryginalny opis (EN)

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.

Jak działa

  1. Core Invariants
  2. Cleaning Up State Bleed Across Batched Tests
  3. Test Verification
Sekcje z nagłówków SKILL.md, w oryginale · 148 linii, 514 słów
Podgląd SKILL.md
---
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

1. **`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.
2. **`@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:

  ```java
  // 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:

```java
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:

```java
ThreadUtils.runOnUiThreadBlocking(() -> {
    SnackbarManager snackbarManager = mSnackbarManagerSupplier.get();
    if (snackbarManager != null) {
        snackbarManager.dismissAllSnackbars();
    }
});
```

### 3. Clearing Dialog Bleed

If modal dialogs remain open across tests:

```java
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:

```java
// 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`:

```bash
./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.
Pliki w paczce (2)
  • OWNERS 1 KB
  • SKILL.md 5 KB

Wersje

W bazie nie ma innych skilli o nazwie android-test-batching.

Migawka bazy z 13.11.2026 · wersja paczki f99dd7b5fb09 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100disable-test
    Prowadzi przez wyłączanie zepsutych lub niestabilnych testów Chromium w C++, Android Java i WebUI.
  • 90Android Test
    Pisze i uruchamia testy jednostkowe i UI na Androidzie, także na telefonie, by sprawdzić ekran lub przepływ.
  • 100reenable-test
    Bada, naprawia i ponownie włącza wyłączone lub niestabilne testy Chromium, weryfikując poprawkę przez TDD i stabilność po wysłaniu.
  • 90java-junit
    Podpowiada wzorce testów JUnit 5 i testów parametryzowanych przy pisaniu i przeglądzie testów jednostkowych w Javie.
  • 100android-java
    Wspiera tworzenie aplikacji na Androida w Javie: klasyczny system widoków, komponenty Jetpack, architektura MVVM i utrzymanie starszych projektów.
  • 90android-ui-analyser
    Testuje, sprawdza i automatyzuje aplikacje Android, iOS, strony i interfejsy Chromium przez AUA: zrzuty, konsolę i sieć.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.