using-robolectric-correctly

using-robolectric-correctly is a skill for Claude Code, Codex from skydoves/android-testing-skills. It costs 208 tokens per session (5,394 once invoked), scanned A, original, Apache-2.0.

Guidance for running Android unit tests on the Java virtual machine with Robolectric, which imitates parts of Android in ordinary Java tests. It covers test runners, Android settings, resources, and simulated system behavior.

In plain words
What is it for?
Use it to test Android code that depends on Context, Resources, Views, package information, or the main task loop. It also helps diagnose common Robolectric setup and configuration errors.
Why use it?
It helps avoid confusing failures caused by using the wrong runner, missing Android resources, or an unadvanced task queue. Tests run without waiting for a physical or emulated device.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/skydoves/android-testing-skills/using-robolectric-correctly
Any agent
npx skills add skydoves/android-testing-skills --skill using-robolectric-correctly
Clone the repo
git clone --depth 1 https://github.com/skydoves/android-testing-skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for using-robolectric-correctly

README.md
[![agentmods](https://agentmods.dev/badge/skills/skydoves/android-testing-skills/using-robolectric-correctly.svg)](https://agentmods.dev/skills/skydoves/android-testing-skills/using-robolectric-correctly)
Your own site
<a href="https://agentmods.dev/skills/skydoves/android-testing-skills/using-robolectric-correctly"><img src="https://agentmods.dev/badge/skills/skydoves/android-testing-skills/using-robolectric-correctly.svg" alt="Measured on agentmods" height="20"></a>
Per session 208 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 5,394 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00208 $0.05394
Opus 5 $0.00104 $0.02697
Sonnet 5 $0.00042 $0.01079
Haiku 4.5 $0.00021 $0.00539

Measured 6d ago against content hash 7d8cf8ce32b2, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

using-robolectric-correctly scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 6d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

jvm-tests/robolectric/using-robolectric-correctly/SKILL.md · 414 lines

How it starts

The opening of the file, as written. The whole thing — 414 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Using Robolectric Correctly — Android On The JVM, Without The Footguns

Robolectric simulates Android on the JVM by swapping in pure-Java reimplementations of system classes ("shadows"). It is fast (10-100x vs an emulator) but not an emulator: no real RenderThread, no real Binder, no real GPU. This skill locks down the runner choice, the @Config matrix, the looper draining ritual, and the AGP 7.2+ sharedTest gotcha. Compose-on-Robolectric specifics live in ../../../compose/synchronization/controlling-the-test-clock/SKILL.md.

When to use this skill

  • The class under test imports android.* (Context, Resources, View, PackageManager, Looper) and the developer wants to test it on the JVM in seconds, not on an emulator in minutes.
  • A unit test fails with RuntimeException: Method ... not mocked (the bare-Android-jar default) — the developer needs Robolectric's shadows.
  • A unit test fails with Resources$NotFoundExceptiontestOptions.unitTests.includeAndroidResources is missing.
  • The developer asks "AndroidJUnit4 vs RobolectricTestRunner — which?".
  • A Handler.postDelayed / Looper queue does not advance under Robolectric's default LooperMode.PAUSED.
  • The developer asks how to run the same test source on JVM and on a device (sharedTest / androidHostTest+androidDeviceTest).
  • Build error after AGP 7.2+: "Source directory ... already added to source set", caused by the classic sharedTest srcDir sharing pattern.

When NOT to use this skill

  • The class under test has zero android.* imports. Robolectric pays a 1-3 s class-load tax for nothing — use plain JUnit4. See ../../runner/configuring-junit4-on-android/SKILL.md.
  • The test verifies pixel correctness, ripple animations, screenshot diffs, accessibility services, or RenderThread timing. Run on an emulator/device. See ../../../instrumentation/runner/running-instrumented-tests-with-androidjunit4/SKILL.md.
  • The test is about coroutines + runTest and does not need framework Android. Use ../../coroutines/testing-coroutines-with-runtest/SKILL.md.
  • The test is about Compose UI rendering. The host-test environment is set up by ../../../compose/setup/configuring-test-dependencies/SKILL.md and the clock semantics live in ../../../compose/synchronization/controlling-the-test-clock/SKILL.md.

Read the full file on GitHub · 414 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 6d ago First seen · 414 lines · 208 tokens per session scan A 7d8cf8ce32b2

Subscribe to this mod's changes

using-robolectric-correctly is a skill published in the GitHub repository skydoves/android-testing-skills (318 stars, last pushed 3mo ago), licensed Apache-2.0. It adds 208 tokens to every session and 5,394 once invoked, about $0.0010 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

java-unit-test

为 Spring Boot 项目生成高质量 Java 单元测试代码。当用户要求"写单元测试"、"生成测试用例"、"帮我写 test"、"补充测试覆盖"、"写 JUnit 测试"、"写 Mockito 测试"、"测试这个 Service / Controller / Mapper"时,必须使用此 skill。即使用户只是说"帮我测一下这个方法"或贴出 Java 代码并问"怎么测",也应触发此 skill。.

hashgraph-online/awesome-codex-plugins · 113 tokens

test-quality

Write high-quality JUnit 5 tests with AssertJ assertions. Use when user says "add tests", "write tests", "improve test coverage", or when reviewing/creating test classes for Java code.

decebals/claude-code-java · 45 tokens

refactor

Refactor Java code in this repo without changing behavior. Not for bug fixes or new features.

membrane/api-gateway · 22 tokens

java-regression-test-generator

Automatically generate regression tests for Java codebases by analyzing changes between old and new code versions. Use when users need to: (1) Generate tests after refactoring or code changes, (2) Ensure previously tested behavior still works in new versions, (3) Cover modified or newly added code paths, (4) Migrate…

ArabelaTso/Skills-4-SE · 111 tokens

eclipse-test

Run JUnit tests in Eclipse projects — all tests, by package, by class, or individual test methods. Also build Maven projects.

gradusnikov/eclipse-chatgpt-plugin · 31 tokens

111-java-maven-dependencies

Use when you need to add or evaluate Maven dependencies that improve code quality or domain modeling — including nullness annotations (JSpecify), static analysis (Error Prone + NullAway), functional programming (VAVR), architecture testing (ArchUnit), or money and currency support (JavaMoney) — and want a…

jabrena/plinth · 133 tokens