write-unit-tests
Skill1.5k starsChanged 2 months agoMITView on GitHub
Use when writing or structuring unit tests or fake test implementations in stripe-android — covers scenarios, Turbine interaction tracking and Flow testing, and Truth assertions
6 other projects use a version of this.
Trending
Quiet this year.thin dataabout the whole repository
Most recently taken up by
- emaraschio/cursor-commandstheir own version, first seen Aug 7, 2026
- kennguyen887/agent-foundationtheir own version, first seen Jun 22, 2026
- josecabralf/skillstheir own version, first seen Jun 5, 2026
- cmnemoi/skillstheir own version, first seen Apr 8, 2026
- gologo13/agent-skillstheir own version, first seen Feb 11, 2026
- namearth5005/claude-skillstheir own version, first seen Dec 13, 2025
Who's talking about stripe/stripe-android
- stripe/stripe-ios“Port Stripe-iOS to Flutter”GitHub · Jan 31, 2019 · 64 reactions
- Adyen/adyen-web“Google Pay - Issue with Maestro - regression from #3539”GitHub · Nov 5, 2025 · 6 reactions
- facebook/facebook-android-sdk“Robolectric is incorrectly specified as non-test dependencies”GitHub · Oct 6, 2022 · 5 reactions
- thebergamo/react-native-fbsdk-next“Upgrade bouncycastle to org.bouncycastle:bcprov-jdk15to18:1.70”GitHub · Oct 5, 2022 · 3 reactions
- PhilipsHue/flutter_reactive_ble“Include our own proguard rules to simplify usages of our library ”GitHub · Nov 18, 2020 · 3 reactions
The biggest 5 of 6 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 6
Talked about on GitHub (6 times).
On GitHub · 6
- Jan 31, 2019Port Stripe-iOS to Flutter — stripe/stripe-ios64 reactions · 8 comments
- Nov 5, 2025Google Pay - Issue with Maestro - regression from #3539 — Adyen/adyen-web6 reactions · 8 comments
- Oct 6, 2022Robolectric is incorrectly specified as non-test dependencies — facebook/facebook-android-sdk5 reactions · 2 comments
- Oct 5, 2022Upgrade bouncycastle to org.bouncycastle:bcprov-jdk15to18:1.70 — thebergamo/react-native-fbsdk-next3 reactions · 6 comments
- Nov 18, 2020Include our own proguard rules to simplify usages of our library — PhilipsHue/flutter_reactive_ble3 reactions
1 more on GitHub
- Feb 10, 2023Opt certain crash reports not to affect crashlytics dashboard — firebase/firebase-android-sdk2 reactions · 1 comment
Other versions6 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 6
- emaraschio/cursor-commands★ 9same name
- namearth5005/claude-skills★ 2same name
- kennguyen887/agent-foundation★ 1same name
- cmnemoi/skills★ 0same name
- gologo13/agent-skills★ 0same name
- josecabralf/skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository8 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- compose-testsSkill
- delegate-low-reasoning-workSkill
- fixing-flakesSkill
- network-testsSkill
- parameterized-testsSkill
- screenshot-testsSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
16 rules. 0 are common, 4 are distinctive, and 12 are very specific to this project.
0
Common
Most of the 6 edited versions we read keep these.
4
Distinctive
This author's own choices. Worth a look.
12
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 8
Use fakes, scenario helpers, and behavior-focused assertions to keep tests reliable and readable.
- Very specific: line 12
Use fakes for production collaborators.
- Distinctive: line 13
If a production collaborator cannot be faked cleanly, stop and propose a testability seam before writing the test.
- Very specific: line 15
Put shared setup in a runScenario helper and validate every fake after the test block.
- Distinctive: line 16
Use Google Truth assertions and prefer field-level assertions when exact object equality is not the contract.
- Very specific: line 18
Test Flow emissions with Turbine's .test { } API.
- Very specific: line 24
All interaction history—including calls, callbacks, and parameterless lifecycle events—must use Turbine.
- Very specific: line 58
Use data classes for calls with parameters and Turbine<Unit> for parameterless calls.
- Very specific: line 80
Create runScenario and Scenario at the bottom of the test file.
- Very specific: line 121
Use runTest directly when shared scenario setup would not help.
- Very specific: line 125
Use assertThat(actual).isEqualTo(expected) from Google Truth.
- Very specific: line 131
Use Turbine's .test { } API for Flow and StateFlow emissions:
- Very specific: line 150
Use runTest, async, and await() so failures propagate.
- Very specific: line 151
Use testScheduler.advanceUntilIdle() to advance to a suspension point.
- Very specific: line 152
After releasing a latch, use await() because OkHttp resumes asynchronously.
- Distinctive: line 154
Use Turbine for StateFlow emission sequences and latches for request ordering.
“Common” is measured: kept by at least 6 in 10 of the 6 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Writing Unit Tests
Use fakes, scenario helpers, and behavior-focused assertions to keep tests reliable and readable.
Core Principles
- Use fakes for production collaborators. Name them
FakeClassName, keep theminternal, and place them in the test source set. - If a production collaborator cannot be faked cleanly, stop and propose a testability seam before writing the test.
- Track every observed fake interaction with Turbine. Mutable properties are only for configuring behavior.
- Put shared setup in a
runScenariohelper and validate every fake after the test block. - Use Google Truth assertions and prefer field-level assertions when exact object equality is not the contract.
- Cover one scenario or configuration per
@Test. - Test Flow emissions with Turbine's
.test { }API.
Creating Fakes
Give fake constructors sensible defaults so tests only specify behavior relevant to the case. Use a companion create() factory when initialization is complex.
All interaction history—including calls, callbacks, and parameterless lifecycle events—must use Turbine. Do not use mutable lists, counters, wasCalled flags, or callback shortcuts. Retrieve a registered callback from its recorded call so the test also proves registration occurred.
internal class FakeLauncher(
var launchResult: Boolean = false,
) : Launcher {
val registerCalls = Turbine<RegisterCall>()
val launchCalls = Turbine<LaunchCall>()
val unregisterCalls = Turbine<Unit>()
override fun register(callback: () -> Unit) {
registerCalls.add(RegisterCall(callback))
}
override fun launch(id: String): Boolean {
launchCalls.add(LaunchCall(id))
return launchResult
}
override fun unregister() {
unregisterCalls.add(Unit)
}
fun ensureAllEventsConsumed() {
registerCalls.ensureAllEventsConsumed()
launchCalls.ensureAllEventsConsumed()
unregisterCalls.ensureAllEventsConsumed()
}
data class RegisterCall(val callback: () -> Unit)
data class LaunchCall(val id: String)
}Use data classes for calls with parameters and Turbine<Unit> for parameterless calls. Consume expected calls with awaitItem(), use expectNoEvents() when no call is expected, and include every owned Turbine in ensureAllEventsConsumed().
For view actions, use ViewActionRecorder<ViewAction> instead of another recording mechanism. Accept it as a constructor or factory parameter with a default when useful:
internal class FakeInteractor(
private val viewActionRecorder: ViewActionRecorder<ViewAction> = ViewActionRecorder(),
) : Interactor {
override fun handleViewAction(viewAction: ViewAction) {
viewActionRecorder.record(viewAction)
}
}Good codebase references are:
paymentsheet/src/test/java/com/stripe/android/paymentsheet/analytics/FakeEventReporter.ktpaymentsheet/src/test/java/com/stripe/android/utils/FakeCustomerRepository.ktpaymentsheet/src/test/java/com/stripe/android/paymentsheet/verticalmode/FakePaymentMethodVerticalLayoutInteractor.kt
Scenario Pattern
Create runScenario and Scenario at the bottom of the test file. Give setup parameters defaults, expose the system under test and fakes through Scenario, and call each fake's ensureAllEventsConsumed() after the block.
class MyFeatureTest {
@Test
fun `fetching data returns success`() = runScenario {
fakeRepository.result = Result.success(testData)
val result = systemUnderTest.fetchData()
assertThat(result.isSuccess).isTrue()
assertThat(fakeRepository.fetchCalls.awaitItem()).isEqualTo(
FetchCall(userId = "123")
)
}
private fun runScenario(
config: Config = defaultConfig,
block: suspend Scenario.() -> Unit,
) = runTest {
val fakeRepository = FakeRepository()
val systemUnderTest = MyFeature(
repository = fakeRepository,
config = config,
)
Scenario(
systemUnderTest = systemUnderTest,
fakeRepository = fakeRepository,
).apply { block() }
fakeRepository.ensureAllEventsConsumed()
}
private data class Scenario(
val systemUnderTest: MyFeature,
val fakeRepository: FakeRepository,
)
}Use runTest directly when shared scenario setup would not help. In that case, validate fakes explicitly.
Assertions and Test Scope
Use assertThat(actual).isEqualTo(expected) from Google Truth. Prefer assertions on meaningful fields because their failures are easier to diagnose; use whole-object equality when exact equality is the behavior under test.
Keep each test focused on one case. Split related configurations into separate tests so one failure does not hide another. Test observable behavior rather than implementation details, and include relevant null, empty, error, and boundary cases. Avoid vacuous assertions by establishing the precondition before testing its removal.
Testing Flows
Use Turbine's .test { } API for Flow and StateFlow emissions:
systemUnderTest.state.test {
assertThat(awaitItem()).isEqualTo(State.Loading)
fakeRepository.emit(newData)
assertThat(awaitItem()).isEqualTo(State.Loaded(newData))
ensureAllEventsConsumed()
}Common operations are awaitItem(), expectNoEvents(), skipItems(n), and ensureAllEventsConsumed().
Concurrency with Real I/O
For coroutine tests involving real NetworkRule or OkHttp I/O:
- Use
runTest,async, andawait()so failures propagate. - Use
testScheduler.advanceUntilIdle()to advance to a suspension point; never useThread.sleep. - After releasing a latch, use
await()because OkHttp resumes asynchronously. - Give every
CountDownLatch.await()in a network response handler a timeout. - Use Turbine for StateFlow emission sequences and latches for request ordering.
- Assert both that a queued request did not arrive while held and that it arrived after release.
Related Skills
- Invoke
parameterized-testsfor parameterized cases. - Invoke
compose-testsfor Compose UI tests. - Invoke
network-testsfor NetworkRule integration tests.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

