network-tests
Skill1.5k starsChanged 2 months agoMITView on GitHub
Use when writing NetworkRule integration tests in stripe-android — covers testBodyFromFile, inline JSON modification, request matchers, and fixture patterns
Trending
Quiet this year.thin dataabout the whole repository
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
In this repository8 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- compose-testsSkill
- delegate-low-reasoning-workSkill
- fixing-flakesSkill
- parameterized-testsSkill
- screenshot-testsSkill
- write-unit-testsSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 3 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 34
When a test needs a modified JSON response, use the testBodyFromFile lambda to modify the base fixture inline — do NOT create a separate …
- Distinctive: line 85
When multiple tests share the same JSON modification, extract the lambda as a parameter:
- Very specific: line 115
Use RequestMatchers (from com.stripe.android.networktesting.RequestMatchers) to validate request body parameters.
- Distinctive: line 153
When one user action triggers several requests asynchronously, enqueue all of those responses immediately before that action, keeping them …
- Distinctive: line 172
When a request doesn't match a mock, the error message shows per-matcher diagnostics with the nearest-miss mock:
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
NetworkRule Integration Tests
For instrumentation tests that need mocked network responses, use NetworkRule (from network-testing module) with testBodyFromFile. JSON fixture files live in the module's src/androidTest/resources/ directory (e.g., paymentsheet/src/androidTest/resources/checkout-session-init.json) and are resolved by filename from the resources root.
Basic Structure
@RunWith(AndroidJUnit4::class)
internal class MyFeatureTest {
@get:Rule
val testRules: TestRules = TestRules.create()
private val networkRule = testRules.networkRule
@Test
fun testSomething() = runPaymentSheetTest(
networkRule = networkRule,
resultCallback = ::assertCompleted,
) { testContext ->
networkRule.enqueue(requestMatcher) { response ->
response.testBodyFromFile("my-fixture.json")
}
// ... test actions ...
}
}Prefer Inline JSON Modification Over New Fixture Files
When a test needs a modified JSON response, use the testBodyFromFile lambda to modify the base fixture inline — do NOT create a separate JSON file for each variation.
// GOOD: Modify the base fixture inline
networkRule.checkoutInit { response ->
response.testBodyFromFile("checkout-session-init.json") { json ->
json.put("customer_email", "session@example.com")
}
}
// BAD: Creating checkout-session-init-with-email.json with one field different
networkRule.checkoutInit { response ->
response.testBodyFromFile("checkout-session-init-with-email.json")
}This keeps the fixture set minimal and makes the test-specific modifications explicit at the call site.
Composing Multiple Modifications
The lambda receives a JSONObject — use standard org.json methods to add or modify fields:
networkRule.checkoutInit { response ->
response.testBodyFromFile("checkout-session-init.json") { json ->
json.put("customer", JSONObject("""
{
"id": "cus_12345",
"payment_methods": [],
"can_detach_payment_method": true
}
""".trimIndent()))
json.put("customer_managed_saved_payment_methods_offer_save", JSONObject("""
{"enabled": true, "status": "not_accepted"}
""".trimIndent()))
}
}For nested modifications, chain getJSONObject():
response.testBodyFromFile("checkout-session-init.json") { json ->
json.getJSONObject("server_built_elements_session_params")
.getJSONObject("deferred_intent")
.put("setup_future_usage", "off_session")
}Extracting Shared Modifiers
When multiple tests share the same JSON modification, extract the lambda as a parameter:
private fun runMyTest(
jsonModifier: (JSONObject) -> Unit = {},
) = runPaymentSheetTest(networkRule = networkRule, resultCallback = ::assertCompleted) { testContext ->
networkRule.checkoutInit { response ->
response.testBodyFromFile("checkout-session-init.json", jsonModifier)
}
// ... shared test logic ...
}
@Test
fun testWithSfu() = runMyTest { json ->
json.getJSONObject("server_built_elements_session_params")
.getJSONObject("deferred_intent")
.put("setup_future_usage", "off_session")
}testBodyFromFile Variants
| Signature | Use when |
testBodyFromFile("file.json") | No modifications needed |
testBodyFromFile("file.json") { json -> ... } | Modifying JSON fields inline |
testBodyFromFile("file.json", replacements) | String-level find/replace with ResponseReplacement |
Request Matchers
Use RequestMatchers (from com.stripe.android.networktesting.RequestMatchers) to validate request body parameters. Import the matchers you need statically:
import com.stripe.android.networktesting.RequestMatchers.bodyPart
import com.stripe.android.networktesting.RequestMatchers.hasBodyPart
import com.stripe.android.networktesting.RequestMatchers.not
networkRule.checkoutConfirm(
bodyPart("expected_amount", "5099"),
not(hasBodyPart("save_payment_method")),
) { response ->
response.testBodyFromFile("checkout-session-confirm.json")
}Enqueue Responses Next to Their Trigger
Enqueue each response immediately before the operation that causes its request. Do not group responses for separate operations at the beginning of a test; doing so obscures which action needs each mock and makes request ordering harder to review.
// Initial load request.
networkRule.enqueue(consumerLookupMatcher) { response ->
response.testBodyFromFile("consumer-session-lookup-success.json")
}
testContext.launch()
// Requests triggered by confirmation and its subsequent refresh.
networkRule.checkoutConfirm { response ->
response.testBodyFromFile("checkout-session-confirm.json")
}
networkRule.checkoutInit { response ->
response.testBodyFromFile("checkout-session-init.json")
}
page.clickConfirm()When one user action triggers several requests asynchronously, enqueue all of those responses immediately before that action, keeping them in the same order as the expected requests.
bodyPart Encoding
bodyPart(), hasBodyPart(), and query(name, value) auto-decode both the matcher arguments and the request body before comparing. Use plain readable strings — urlEncode() is unnecessary:
// Keys with brackets and values with special characters — just use plain strings
bodyPart("billing_details[email]", "user@example.com")
bodyPart("billing_details[address][line1]", "123 Main St")
bodyPart("payment_method_data[allow_redisplay]", "unspecified")
// urlEncode() still works (backward compatible) but is unnecessary
// bodyPart(urlEncode("billing_details[email]"), urlEncode("user@example.com"))Mismatch Debugging
When a request doesn't match a mock, the error message shows per-matcher diagnostics with the nearest-miss mock:
POST https://localhost/v1/payment_intents/pi_123/confirm
Body params: {billing_details[email]=actual@test.com, payment_method=pm_123}
Nearest mock: composite(path(/v1/confirm), bodyPart(billing_details[email], expected@test.com))
+ PASS: path(/v1/confirm)
+ PASS: method(POST)
- FAIL: bodyPart(billing_details[email], expected@test.com)See PaymentSheetBillingConfigurationTest.kt for more examples.
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.

