[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6D286E8T3BNPB8H99T1B806":3,"skill-same:01M6D286E8T3BNPB8H99T1B806":67},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":39,"linkOnly":40,"markdownContent":41,"markdownBody":42,"frontMatter":43,"refName":44,"commitSha":45,"skillDirectory":46,"forksCount":47,"repositoryHtmlUrl":48,"repositoryHomepageUrl":49,"ownerHtmlUrl":50,"ownerBlogUrl":49,"ownerDescription":51,"updatedAt":52,"install":53,"resources":66},"01M6D286E8T3BNPB8H99T1B806","testing-integration",null,"Integration tests against real boundaries: the HTTP layer and a real database, containers for dependencies, isolating tests with transactions or fresh schemas, seeding, faking other services at the network edge, contract tests between services, testing migrations, controlling time, and keeping them fast enough to run on every change. Read before writing tests that cross a process or network boundary.","enowdev\u002Fenowxcli","enowdev","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F179420349?v=4","01M6D1MVX2KC0X3Z9NESE7P22K","Enow Dev.","01M6D1MW1FMZGBDKWAJY4GQX81",67,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli\u002Fblob\u002Fmain\u002Fcrates\u002Fenowx-core\u002Fskills\u002Ftesting-integration\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38],"testing integration","integration","testing","edge","tests","contract","time","read","transactions","boundary","network","services","database","writing tests","run","http","integration tests","change","containers","writing","2026-11-10 10:12:30",false,"---\nname: testing-integration\ndescription: \"Integration tests against real boundaries: the HTTP layer and a real database, containers for dependencies, isolating tests with transactions or fresh schemas, seeding, faking other services at the network edge, contract tests between services, testing migrations, controlling time, and keeping them fast enough to run on every change. Read before writing tests that cross a process or network boundary.\"\n---\n\n# Integration tests against real boundaries\n\nThe naive version mocks the ORM and the HTTP client, lets SQLite stand in for\nPostgreSQL, shares one test database that every test and developer writes\nto, and calls a real sandbox API from the suite. It stays green while the SQL\nis wrong, a constraint is missing or a date is serialised in the wrong zone,\nand it fails when two people run it at once. This skill: which boundaries to\ntest for real, how to provide them, how to isolate tests, how to fake what\nyou do not own, and how to keep it fast. Endpoint-by-endpoint cases for\nservers are in `backend-testing`; principles in `testing`.\n\n## 1. What to cover\n\n| Boundary | Check |\n|---|---|\n| Routing and HTTP | the route, method, status, headers (`Location`, `Retry-After`), body shape |\n| Validation | invalid input gives `400` or `422` with every field error; unknown fields refused |\n| Auth | `401` without credentials; `403` or `404` for another user's record, which stays untouched |\n| Queries | the right rows for filters, joins, sort order and pagination; no N+1 (count queries) |\n| Constraints | unique, foreign key and check constraints map to the documented error (`409`) |\n| Transactions | a failure halfway leaves nothing written |\n| Serialisation | ISO 8601 times in UTC, money as integers, ids as strings, nulls, enum names |\n| Error mapping | a dependency's timeout or `500` becomes the documented status, with nothing half-done |\n| Jobs and events | enqueued with the right payload; the handler's effect when run |\n| Caches | invalidated after a write |\n\nOne test per behaviour, failure paths included, through the framework's test\nclient (`app.request()`, `fastify.inject`, `httpx.AsyncClient`, `MockMvc`).\n\n## 2. Real dependencies, started once\n\n- The same engine and major version as production: PostgreSQL 17 in tests if\n  production runs 17. Not SQLite or H2 standing in for PostgreSQL or MySQL:\n  `ON CONFLICT`, JSONB, locking, collation and case rules differ.\n- Testcontainers starts containers from the test code on random free ports\n  and removes them afterwards (its Ryuk reaper), in Java, Go, Node, Python,\n  .NET and Rust. It needs Docker or a compatible runtime (Podman, Colima,\n  OrbStack) or Testcontainers Cloud.\n- Or compose and CI job services, with tests reading `DATABASE_URL`.\n- Start once per run (at most once per worker), never per test: a database\n  container takes seconds. Per-test isolation comes from section 3.\n\n```ts\n\u002F\u002F test\u002Fglobal-setup.ts (Vitest globalSetup)\nimport { PostgreSqlContainer } from \"@testcontainers\u002Fpostgresql\";\nimport type { TestProject } from \"vitest\u002Fnode\";\n\nexport default async function setup(project: TestProject) {\n  const pg = await new PostgreSqlContainer(\"postgres:17-alpine\").start();\n  await migrate(pg.getConnectionUri());\n  project.provide(\"databaseUrl\", pg.getConnectionUri()); \u002F\u002F inject(\"databaseUrl\") in tests\n  return async () => { await pg.stop(); };\n}\n\ndeclare module \"vitest\" {\n  export interface ProvidedContext { databaseUrl: string }\n}\n```\n\n```python\n# conftest.py (recent releases also offer testcontainers.community.postgres)\nfrom testcontainers.postgres import PostgresContainer\n\n@pytest.fixture(scope=\"session\")\ndef database_url():\n    with PostgresContainer(\"postgres:17-alpine\", driver=\"psycopg\") as pg:\n        url = pg.get_connection_url()\n        run_migrations(url)\n        yield url\n```\n\n```go\nfunc TestMain(m *testing.M) {\n\tctx := context.Background()\n\tpg, err := postgres.Run(ctx, \"postgres:17-alpine\",\n\t\tpostgres.WithDatabase(\"app_test\"),\n\t\tpostgres.BasicWaitStrategies(),\n\t)\n\tif err != nil {\n\t\tlog.Fatalf(\"start postgres: %v\", err)\n\t}\n\tdsn = pg.MustConnectionString(ctx, \"sslmode=disable\")\n\tif err := migrateUp(dsn); err != nil {\n\t\tlog.Fatalf(\"migrate: %v\", err)\n\t}\n\tcode := m.Run()\n\t_ = testcontainers.TerminateContainer(pg) \u002F\u002F os.Exit skips deferred calls\n\tos.Exit(code)\n}\n```\n\n- Java: `@Testcontainers` with `@Container @ServiceConnection static\n  PostgreSQLContainer postgres = new PostgreSQLContainer(\"postgres:17-alpine\");`\n  in Spring Boot (the class is in `org.testcontainers.postgresql` from\n  Testcontainers 2.0, in `org.testcontainers.containers` before).\n- .NET: `new PostgreSqlBuilder(\"postgres:17-alpine\").Build()` started in a\n  class fixture, the app through `WebApplicationFactory\u003CProgram>`, Respawn to\n  reset data between tests.\n- Rust: `#[sqlx::test]` gives each test a fresh database from `DATABASE_URL`\n  with `migrations\u002F` applied; `testcontainers-modules` provides the server.\n- Container reuse (`testcontainers.reuse.enable=true`) is for local runs only.\n\n## 3. Isolating tests from each other\n\n| Strategy | Good | Costs |\n|---|---|---|\n| Transaction per test, rolled back | fastest; nothing to clean | the app must use the test's connection, not its own pool; commit-time behaviour never runs; code with its own transactions needs savepoints; no concurrency tests |\n| Truncate between tests | real commits, pools and threads work | slower as tables grow; parallel workers need separate databases |\n| Template database cloned per test or worker | real commits, parallel-safe, fresh state | PostgreSQL-specific; nothing may be connected to the template while cloning |\n| Schema per worker | one database, parallel workers | migrations must not hard-code the schema |\n\n- Use the framework's own first: Django `TestCase` (transaction) and\n  `TransactionTestCase` (truncation), pytest-django\n  `django_db(transaction=True)`, Rails transactional tests, Laravel\n  `RefreshDatabase` and `DatabaseTruncation`, Spring's `@Transactional`\n  tests, Respawn in .NET.\n- Transaction-per-test traps: `on_commit` hooks never fire (Django:\n  `captureOnCommitCallbacks(execute=True)`; pytest-django:\n  `django_capture_on_commit_callbacks`); PostgreSQL's `now()` is the\n  transaction's start time, so it is the same for the whole test; a Spring\n  `@Transactional` test with `webEnvironment = RANDOM_PORT` does not roll\n  back what the server thread committed.\n- Truncation in one statement, with the table list read once from\n  `pg_tables` (minus the migrations table):\n  `TRUNCATE orders, order_items, customers RESTART IDENTITY CASCADE;`\n- Templates: pgtestdb (Go) and `#[sqlx::test]` (Rust) create a database per\n  test from a migrated template; Testcontainers' PostgreSQL modules can\n  `snapshot()` and `restoreSnapshot()` (Node) or `Snapshot` and `Restore`\n  (Go) the migrated state.\n- Parallel workers each get their own database or schema: pytest-xdist's\n  `worker_id` fixture (`gw0`, `gw1`, or `master`), Laravel's\n  `--parallel` databases suffixed per process. `go test .\u002F...` runs\n  packages as parallel processes, so each package's `TestMain` needs its own\n  database or container.\n- Seeding: reference data (roles, plans) once, with the migrations; the rest\n  per test from factories with unique values (`testing-data`).\n\n## 4. Other services, faked at the network edge\n\n- Never call a real third-party API from the suite: rate limits, cost,\n  flakiness and secrets in CI. Fake it at HTTP, so the real client code\n  (serialisation, headers, retries, timeouts) runs.\n- Tools: MSW's `setupServer` (fail on unhandled requests with\n  `onUnhandledRequest: \"error\"` in MSW 2, `onUnhandledFrame: \"error\"` in\n  MSW 3), nock, undici `MockAgent`; respx for httpx, responses for requests,\n  pytest-httpserver; `httptest.NewServer` in Go; WireMock or MockWebServer on\n  the JVM; WireMock.Net; the `wiremock` crate; Laravel `Http::fake()` with\n  `Http::preventStrayRequests()`.\n- Block real network access so a forgotten fake fails loudly: MSW's\n  unhandled setting, `pytest --disable-socket --allow-hosts=127.0.0.1,localhost`\n  (pytest-socket), `WebMock.disable_net_connect!(allow_localhost: true)`.\n- Fake the failures too: a timeout, a reset connection, `429` with\n  `Retry-After`, `500`, malformed JSON, a reply slower than the client's\n  timeout. Check the retry count and that nothing was half-written.\n- Cloud APIs: LocalStack for AWS, Azurite for Azure Storage, the Google\n  Cloud emulators (Pub\u002FSub, Firestore, Spanner), DynamoDB Local, the\n  Firebase Emulator Suite, all as containers.\n- Recorded cassettes (pytest-recording, VCR, Polly.JS) only with credentials\n  filtered out; hand-written fakes read better for failure cases.\n\n```python\n@respx.mock\ndef test_payment_stays_pending_when_the_provider_times_out(client, order):\n    respx.post(\"https:\u002F\u002Fpayments.example.test\u002Fv1\u002Fcharges\").mock(side_effect=httpx.ConnectTimeout)\n\n    res = client.post(f\"\u002Forders\u002F{order.id}\u002Fpay\")\n\n    assert res.status_code == 503\n    assert fetch_order(order.id).status == \"pending\"\n```\n\n## 5. Contracts between services\n\n- When a consumer and a provider deploy separately, a contract test checks\n  the provider still gives what the consumer uses, without a shared\n  environment.\n- Consumer-driven with Pact: the consumer's tests run against a Pact mock\n  server and write a pact file; the provider replays it against the real\n  service with provider states set up; a broker (Pact Broker or PactFlow)\n  stores pacts and results, and `can-i-deploy` gates each deploy.\n\n```ts\nimport { PactV4, MatchersV3 } from \"@pact-foundation\u002Fpact\";\n\nconst pact = new PactV4({ consumer: \"web\", provider: \"orders-api\" });\n\nit(\"reads an order\", () =>\n  pact\n    .addInteraction()\n    .given(\"order ord_1 exists\")\n    .uponReceiving(\"a request for order ord_1\")\n    .withRequest(\"GET\", \"\u002Forders\u002Ford_1\")\n    .willRespondWith(200, (res) =>\n      res.jsonBody({ id: \"ord_1\", status: MatchersV3.regex(\"paid|pending\", \"paid\"), total: MatchersV3.integer(1500) }),\n    )\n    .executeTest(async (server) => {\n      const order = await new OrdersClient(server.url).get(\"ord_1\");\n      expect(order.status).toBe(\"paid\");\n    }));\n```\n\n- Schema-based, when one team owns both sides or the API is public: generate\n  OpenAPI from the code, generate or check the client from it, catch\n  breaking changes with `oasdiff breaking base.yaml head.yaml`, and let\n  Schemathesis generate requests from the schema:\n  `schemathesis run http:\u002F\u002Flocalhost:8000\u002Fopenapi.json --checks all`.\n\n## 6. Migrations\n\n- CI runs every migration from an empty database before the tests (the\n  setup above does).\n- Reversible migrations go up, down and up again on a copy\n  (`alembic upgrade head && alembic downgrade -1 && alembic upgrade head`,\n  `bin\u002Frails db:migrate:redo`).\n- Models and migrations agree: `alembic check`,\n  `python manage.py makemigrations --check --dry-run`, or the ORM's\n  equivalent, in CI.\n- Data migrations run on generated data of production's shape (never copied\n  personal data), asserting counts and a few transformed rows.\n- Locks: lint with squawk (PostgreSQL) or strong_migrations (Rails); time a\n  large-table rewrite against generated volume.\n\n## 7. Time, background work and concurrency\n\n- Inject a clock into the app and freeze it in the test (`testing-data`).\n  The database has its own clock: set timestamps explicitly in inserted rows\n  when a test depends on them.\n- Background work runs inline or is drained, then its effect is asserted:\n  Rails `perform_enqueued_jobs`, `Sidekiq::Testing.inline!`, Laravel\n  `Queue::fake()` with `Queue::assertPushed()` (or the `sync` connection),\n  Celery `task.apply()`, River's `rivertest.RequireInserted`, a BullMQ\n  processor called with the job's data. More in `backend-jobs`.\n- Wait for eventual effects by polling with a timeout (Awaitility,\n  `vi.waitFor`, testify `assert.Eventually`), never a `sleep`.\n- Unique keys per worker for everything shared: Redis prefixes, queue\n  names, bucket prefixes. Never hard-code a port.\n- Races are tested with real concurrency against the real database (not\n  inside a rolled-back transaction):\n\n```ts\nit(\"sells the last item once when two orders race\", async () => {\n  const product = await createProduct({ stock: 1 });\n\n  const results = await Promise.all([placeOrder(product.id), placeOrder(product.id)]);\n\n  expect(results.map((r) => r.status).sort()).toEqual([201, 409]);\n  expect((await getProduct(product.id)).stock).toBe(0);\n});\n```\n\n## 8. Keeping it fast\n\n- Containers once per run, migrations once (into a template or snapshot), a\n  cheap reset per test; a reset costing more than the test is next to fix.\n- Aim for one service's suite in a few minutes locally; past about 10, shard\n  in CI (`testing-ci`) and hunt per-test containers, re-migrations, sleeps.\n- Find the slow ones: `pytest --durations=10`, `gotestsum tool slowest`,\n  nextest's `SLOW` lines.\n\n## Check it\n\n- Run in random order and in parallel (`pytest -p randomly -n auto`,\n  `vitest run --sequence.shuffle`, `go test -shuffle=on -p 4 .\u002F...`): green.\n- Break the SQL (a wrong join condition) or drop a constraint: a test fails.\n- With the network blocked, nothing reaches the internet.\n- `docker ps` after the run shows no leftover containers.\n\n## Avoid\n\nSQLite or H2 standing in for the production database; mocks of the ORM or\nquery builder; one shared database for all tests and developers; a\ncontainer per test; hard-coded ports; tests that depend on order; calling\nreal providers from CI; transaction-per-test when the code commits, uses its\nown pool or relies on `on_commit`; `sleep` to wait for a job.\n","# Integration tests against real boundaries\n\nThe naive version mocks the ORM and the HTTP client, lets SQLite stand in for\nPostgreSQL, shares one test database that every test and developer writes\nto, and calls a real sandbox API from the suite. It stays green while the SQL\nis wrong, a constraint is missing or a date is serialised in the wrong zone,\nand it fails when two people run it at once. This skill: which boundaries to\ntest for real, how to provide them, how to isolate tests, how to fake what\nyou do not own, and how to keep it fast. Endpoint-by-endpoint cases for\nservers are in `backend-testing`; principles in `testing`.\n\n## 1. What to cover\n\n| Boundary | Check |\n|---|---|\n| Routing and HTTP | the route, method, status, headers (`Location`, `Retry-After`), body shape |\n| Validation | invalid input gives `400` or `422` with every field error; unknown fields refused |\n| Auth | `401` without credentials; `403` or `404` for another user's record, which stays untouched |\n| Queries | the right rows for filters, joins, sort order and pagination; no N+1 (count queries) |\n| Constraints | unique, foreign key and check constraints map to the documented error (`409`) |\n| Transactions | a failure halfway leaves nothing written |\n| Serialisation | ISO 8601 times in UTC, money as integers, ids as strings, nulls, enum names |\n| Error mapping | a dependency's timeout or `500` becomes the documented status, with nothing half-done |\n| Jobs and events | enqueued with the right payload; the handler's effect when run |\n| Caches | invalidated after a write |\n\nOne test per behaviour, failure paths included, through the framework's test\nclient (`app.request()`, `fastify.inject`, `httpx.AsyncClient`, `MockMvc`).\n\n## 2. Real dependencies, started once\n\n- The same engine and major version as production: PostgreSQL 17 in tests if\n  production runs 17. Not SQLite or H2 standing in for PostgreSQL or MySQL:\n  `ON CONFLICT`, JSONB, locking, collation and case rules differ.\n- Testcontainers starts containers from the test code on random free ports\n  and removes them afterwards (its Ryuk reaper), in Java, Go, Node, Python,\n  .NET and Rust. It needs Docker or a compatible runtime (Podman, Colima,\n  OrbStack) or Testcontainers Cloud.\n- Or compose and CI job services, with tests reading `DATABASE_URL`.\n- Start once per run (at most once per worker), never per test: a database\n  container takes seconds. Per-test isolation comes from section 3.\n\n```ts\n\u002F\u002F test\u002Fglobal-setup.ts (Vitest globalSetup)\nimport { PostgreSqlContainer } from \"@testcontainers\u002Fpostgresql\";\nimport type { TestProject } from \"vitest\u002Fnode\";\n\nexport default async function setup(project: TestProject) {\n  const pg = await new PostgreSqlContainer(\"postgres:17-alpine\").start();\n  await migrate(pg.getConnectionUri());\n  project.provide(\"databaseUrl\", pg.getConnectionUri()); \u002F\u002F inject(\"databaseUrl\") in tests\n  return async () => { await pg.stop(); };\n}\n\ndeclare module \"vitest\" {\n  export interface ProvidedContext { databaseUrl: string }\n}\n```\n\n```python\n# conftest.py (recent releases also offer testcontainers.community.postgres)\nfrom testcontainers.postgres import PostgresContainer\n\n@pytest.fixture(scope=\"session\")\ndef database_url():\n    with PostgresContainer(\"postgres:17-alpine\", driver=\"psycopg\") as pg:\n        url = pg.get_connection_url()\n        run_migrations(url)\n        yield url\n```\n\n```go\nfunc TestMain(m *testing.M) {\n\tctx := context.Background()\n\tpg, err := postgres.Run(ctx, \"postgres:17-alpine\",\n\t\tpostgres.WithDatabase(\"app_test\"),\n\t\tpostgres.BasicWaitStrategies(),\n\t)\n\tif err != nil {\n\t\tlog.Fatalf(\"start postgres: %v\", err)\n\t}\n\tdsn = pg.MustConnectionString(ctx, \"sslmode=disable\")\n\tif err := migrateUp(dsn); err != nil {\n\t\tlog.Fatalf(\"migrate: %v\", err)\n\t}\n\tcode := m.Run()\n\t_ = testcontainers.TerminateContainer(pg) \u002F\u002F os.Exit skips deferred calls\n\tos.Exit(code)\n}\n```\n\n- Java: `@Testcontainers` with `@Container @ServiceConnection static\n  PostgreSQLContainer postgres = new PostgreSQLContainer(\"postgres:17-alpine\");`\n  in Spring Boot (the class is in `org.testcontainers.postgresql` from\n  Testcontainers 2.0, in `org.testcontainers.containers` before).\n- .NET: `new PostgreSqlBuilder(\"postgres:17-alpine\").Build()` started in a\n  class fixture, the app through `WebApplicationFactory\u003CProgram>`, Respawn to\n  reset data between tests.\n- Rust: `#[sqlx::test]` gives each test a fresh database from `DATABASE_URL`\n  with `migrations\u002F` applied; `testcontainers-modules` provides the server.\n- Container reuse (`testcontainers.reuse.enable=true`) is for local runs only.\n\n## 3. Isolating tests from each other\n\n| Strategy | Good | Costs |\n|---|---|---|\n| Transaction per test, rolled back | fastest; nothing to clean | the app must use the test's connection, not its own pool; commit-time behaviour never runs; code with its own transactions needs savepoints; no concurrency tests |\n| Truncate between tests | real commits, pools and threads work | slower as tables grow; parallel workers need separate databases |\n| Template database cloned per test or worker | real commits, parallel-safe, fresh state | PostgreSQL-specific; nothing may be connected to the template while cloning |\n| Schema per worker | one database, parallel workers | migrations must not hard-code the schema |\n\n- Use the framework's own first: Django `TestCase` (transaction) and\n  `TransactionTestCase` (truncation), pytest-django\n  `django_db(transaction=True)`, Rails transactional tests, Laravel\n  `RefreshDatabase` and `DatabaseTruncation`, Spring's `@Transactional`\n  tests, Respawn in .NET.\n- Transaction-per-test traps: `on_commit` hooks never fire (Django:\n  `captureOnCommitCallbacks(execute=True)`; pytest-django:\n  `django_capture_on_commit_callbacks`); PostgreSQL's `now()` is the\n  transaction's start time, so it is the same for the whole test; a Spring\n  `@Transactional` test with `webEnvironment = RANDOM_PORT` does not roll\n  back what the server thread committed.\n- Truncation in one statement, with the table list read once from\n  `pg_tables` (minus the migrations table):\n  `TRUNCATE orders, order_items, customers RESTART IDENTITY CASCADE;`\n- Templates: pgtestdb (Go) and `#[sqlx::test]` (Rust) create a database per\n  test from a migrated template; Testcontainers' PostgreSQL modules can\n  `snapshot()` and `restoreSnapshot()` (Node) or `Snapshot` and `Restore`\n  (Go) the migrated state.\n- Parallel workers each get their own database or schema: pytest-xdist's\n  `worker_id` fixture (`gw0`, `gw1`, or `master`), Laravel's\n  `--parallel` databases suffixed per process. `go test .\u002F...` runs\n  packages as parallel processes, so each package's `TestMain` needs its own\n  database or container.\n- Seeding: reference data (roles, plans) once, with the migrations; the rest\n  per test from factories with unique values (`testing-data`).\n\n## 4. Other services, faked at the network edge\n\n- Never call a real third-party API from the suite: rate limits, cost,\n  flakiness and secrets in CI. Fake it at HTTP, so the real client code\n  (serialisation, headers, retries, timeouts) runs.\n- Tools: MSW's `setupServer` (fail on unhandled requests with\n  `onUnhandledRequest: \"error\"` in MSW 2, `onUnhandledFrame: \"error\"` in\n  MSW 3), nock, undici `MockAgent`; respx for httpx, responses for requests,\n  pytest-httpserver; `httptest.NewServer` in Go; WireMock or MockWebServer on\n  the JVM; WireMock.Net; the `wiremock` crate; Laravel `Http::fake()` with\n  `Http::preventStrayRequests()`.\n- Block real network access so a forgotten fake fails loudly: MSW's\n  unhandled setting, `pytest --disable-socket --allow-hosts=127.0.0.1,localhost`\n  (pytest-socket), `WebMock.disable_net_connect!(allow_localhost: true)`.\n- Fake the failures too: a timeout, a reset connection, `429` with\n  `Retry-After`, `500`, malformed JSON, a reply slower than the client's\n  timeout. Check the retry count and that nothing was half-written.\n- Cloud APIs: LocalStack for AWS, Azurite for Azure Storage, the Google\n  Cloud emulators (Pub\u002FSub, Firestore, Spanner), DynamoDB Local, the\n  Firebase Emulator Suite, all as containers.\n- Recorded cassettes (pytest-recording, VCR, Polly.JS) only with credentials\n  filtered out; hand-written fakes read better for failure cases.\n\n```python\n@respx.mock\ndef test_payment_stays_pending_when_the_provider_times_out(client, order):\n    respx.post(\"https:\u002F\u002Fpayments.example.test\u002Fv1\u002Fcharges\").mock(side_effect=httpx.ConnectTimeout)\n\n    res = client.post(f\"\u002Forders\u002F{order.id}\u002Fpay\")\n\n    assert res.status_code == 503\n    assert fetch_order(order.id).status == \"pending\"\n```\n\n## 5. Contracts between services\n\n- When a consumer and a provider deploy separately, a contract test checks\n  the provider still gives what the consumer uses, without a shared\n  environment.\n- Consumer-driven with Pact: the consumer's tests run against a Pact mock\n  server and write a pact file; the provider replays it against the real\n  service with provider states set up; a broker (Pact Broker or PactFlow)\n  stores pacts and results, and `can-i-deploy` gates each deploy.\n\n```ts\nimport { PactV4, MatchersV3 } from \"@pact-foundation\u002Fpact\";\n\nconst pact = new PactV4({ consumer: \"web\", provider: \"orders-api\" });\n\nit(\"reads an order\", () =>\n  pact\n    .addInteraction()\n    .given(\"order ord_1 exists\")\n    .uponReceiving(\"a request for order ord_1\")\n    .withRequest(\"GET\", \"\u002Forders\u002Ford_1\")\n    .willRespondWith(200, (res) =>\n      res.jsonBody({ id: \"ord_1\", status: MatchersV3.regex(\"paid|pending\", \"paid\"), total: MatchersV3.integer(1500) }),\n    )\n    .executeTest(async (server) => {\n      const order = await new OrdersClient(server.url).get(\"ord_1\");\n      expect(order.status).toBe(\"paid\");\n    }));\n```\n\n- Schema-based, when one team owns both sides or the API is public: generate\n  OpenAPI from the code, generate or check the client from it, catch\n  breaking changes with `oasdiff breaking base.yaml head.yaml`, and let\n  Schemathesis generate requests from the schema:\n  `schemathesis run http:\u002F\u002Flocalhost:8000\u002Fopenapi.json --checks all`.\n\n## 6. Migrations\n\n- CI runs every migration from an empty database before the tests (the\n  setup above does).\n- Reversible migrations go up, down and up again on a copy\n  (`alembic upgrade head && alembic downgrade -1 && alembic upgrade head`,\n  `bin\u002Frails db:migrate:redo`).\n- Models and migrations agree: `alembic check`,\n  `python manage.py makemigrations --check --dry-run`, or the ORM's\n  equivalent, in CI.\n- Data migrations run on generated data of production's shape (never copied\n  personal data), asserting counts and a few transformed rows.\n- Locks: lint with squawk (PostgreSQL) or strong_migrations (Rails); time a\n  large-table rewrite against generated volume.\n\n## 7. Time, background work and concurrency\n\n- Inject a clock into the app and freeze it in the test (`testing-data`).\n  The database has its own clock: set timestamps explicitly in inserted rows\n  when a test depends on them.\n- Background work runs inline or is drained, then its effect is asserted:\n  Rails `perform_enqueued_jobs`, `Sidekiq::Testing.inline!`, Laravel\n  `Queue::fake()` with `Queue::assertPushed()` (or the `sync` connection),\n  Celery `task.apply()`, River's `rivertest.RequireInserted`, a BullMQ\n  processor called with the job's data. More in `backend-jobs`.\n- Wait for eventual effects by polling with a timeout (Awaitility,\n  `vi.waitFor`, testify `assert.Eventually`), never a `sleep`.\n- Unique keys per worker for everything shared: Redis prefixes, queue\n  names, bucket prefixes. Never hard-code a port.\n- Races are tested with real concurrency against the real database (not\n  inside a rolled-back transaction):\n\n```ts\nit(\"sells the last item once when two orders race\", async () => {\n  const product = await createProduct({ stock: 1 });\n\n  const results = await Promise.all([placeOrder(product.id), placeOrder(product.id)]);\n\n  expect(results.map((r) => r.status).sort()).toEqual([201, 409]);\n  expect((await getProduct(product.id)).stock).toBe(0);\n});\n```\n\n## 8. Keeping it fast\n\n- Containers once per run, migrations once (into a template or snapshot), a\n  cheap reset per test; a reset costing more than the test is next to fix.\n- Aim for one service's suite in a few minutes locally; past about 10, shard\n  in CI (`testing-ci`) and hunt per-test containers, re-migrations, sleeps.\n- Find the slow ones: `pytest --durations=10`, `gotestsum tool slowest`,\n  nextest's `SLOW` lines.\n\n## Check it\n\n- Run in random order and in parallel (`pytest -p randomly -n auto`,\n  `vitest run --sequence.shuffle`, `go test -shuffle=on -p 4 .\u002F...`): green.\n- Break the SQL (a wrong join condition) or drop a constraint: a test fails.\n- With the network blocked, nothing reaches the internet.\n- `docker ps` after the run shows no leftover containers.\n\n## Avoid\n\nSQLite or H2 standing in for the production database; mocks of the ORM or\nquery builder; one shared database for all tests and developers; a\ncontainer per test; hard-coded ports; tests that depend on order; calling\nreal providers from CI; transaction-per-test when the code commits, uses its\nown pool or relies on `on_commit`; `sleep` to wait for a job.\n",{"name":5,"description":7},"main","38293fe1b096e6bf3646c7344c38786ed688f464","crates\u002Fenowx-core\u002Fskills\u002Ftesting-integration",21,"https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli","https:\u002F\u002Fenowx.ai","https:\u002F\u002Fgithub.com\u002Fenowdev","Pretending to be a Developer","2026-10-06 02:05:35",{"source":8,"skillName":5,"commands":54,"prompt":64,"zipAvailable":65},[55,58,61],{"tool":56,"command":57},"npx","npx skills add enowdev\u002Fenowxcli --skill testing-integration",{"tool":59,"command":60},"bunx","bunx skills add enowdev\u002Fenowxcli --skill testing-integration",{"tool":62,"command":63},"pnpm","pnpm dlx skills add enowdev\u002Fenowxcli --skill testing-integration","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli\u002Fblob\u002Fmain\u002Fcrates\u002Fenowx-core\u002Fskills\u002Ftesting-integration\u002FSKILL.md",true,[],[68,78,94,107,128,147],{"skillNo":69,"name":70,"nameZh":6,"description":71,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":72,"categories":73,"keywords":74,"publishedAt":39},"01M6D2HQYSQD9N7MTNDT4A7CBM","demo-skill","Project-scope demo skill for tests.","https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli\u002Fblob\u002Fmain\u002Fworkspace\u002F.agents\u002Fskills\u002Fdemo-skill\u002FSKILL.md",[],[75,76,23,77,26],"demo skill","demo","project",{"skillNo":79,"name":38,"nameZh":6,"description":80,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":81,"categories":82,"keywords":83,"publishedAt":39},"01M6D2HM0GCPM0TM2HPG9HHR2R","Writing words people read: the specific thing instead of claims, words to drop, sentences, interface copy (buttons, labels, errors, empty states, confirmations), page copy, notifications and emails, alt text and link text, numbers and dates, words that translate well, documentation and voice. Read before writing a page's copy, an interface's text or a document.","https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli\u002Fblob\u002Fmain\u002Fcrates\u002Fenowx-core\u002Fskills\u002Fwriting\u002FSKILL.md",[],[38,84,85,86,87,88,26,89,90,91,92,93],"text","emails","empty","drop","document","page","voice","notifications","documentation","translate",{"skillNo":95,"name":96,"nameZh":6,"description":97,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":98,"categories":99,"keywords":100,"publishedAt":39},"01M6D2HG07YS49NM196Q0R3AZ8","ui","Designing or restyling an interface: direction, layout, type, colour, icons, components, states, responsive behaviour. Read before building a page, a screen or a set of components.","https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli\u002Fblob\u002Fmain\u002Fcrates\u002Fenowx-core\u002Fskills\u002Fui\u002FSKILL.md",[],[96,101,102,103,104,89,105,26,106],"icons","components","SET","responsive","layout","before building",{"skillNo":108,"name":109,"nameZh":6,"description":110,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":111,"categories":112,"keywords":113,"publishedAt":39},"01M6D2HB59HZHWG1RYZDV4SJ91","ui-themes","Light and dark themes, and colour that holds in both: tokens with a value per theme, and what each kind of content needs to stay visible (icons, SVG drawings and line art, logos, photos, screenshots, charts, code, maps, borders, shadows, focus, form controls), switching without a flash, and checking both. Read before building a second theme or a theme toggle, and before any drawing, logo or chart on a page that has two themes.","https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli\u002Fblob\u002Fmain\u002Fcrates\u002Fenowx-core\u002Fskills\u002Fui-themes\u002FSKILL.md",[],[96,114,115,116,117,118,119,120,121,26,106,122,89,123,124,125,101,126,127],"ui themes","switching","photos","tokens","drawing","focus","maps","Art","flash","code","Charts","content","screenshots","logo",{"skillNo":129,"name":130,"nameZh":6,"description":131,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":132,"categories":133,"keywords":134,"publishedAt":39},"01M6D2H5R5KRAE524C8QX0T7Q0","ui-structure","Structure before styling: the blueprint written before any interface code (the screen's job, the regions its kind of page needs, their order and why, the layout skeleton in numbers, the components and their states), the anatomy and order of a homepage, a dashboard, a list, a detail page, settings, a form, sign-in, pricing, docs, an article and a checkout, and how to turn the blueprint into code (tokens, layout primitives, components, sections, page). Read first, before building or rebuilding any page or screen.","https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli\u002Fblob\u002Fmain\u002Fcrates\u002Fenowx-core\u002Fskills\u002Fui-structure\u002FSKILL.md",[],[135,96,136,102,137,138,123,139,140,141,105,117,142,143,144,26,106,89,145,146],"structure","ui structure","pricing","dashboard","Blueprint","article","anatomy","styling","primitives","list","why","how",{"skillNo":148,"name":149,"nameZh":6,"description":150,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":151,"categories":152,"keywords":153,"publishedAt":39},"01M6D2H0ZZBJG77MBGPZHA6MWD","ui-stack-vue","Building interfaces in Vue 3 and Nuxt: project layout, script setup with typed defineProps, defineEmits and defineModel, attribute fallthrough, slots and scoped slots, template refs, ref, reactive and computed, watch versus watchEffect, composables and VueUse, provide and inject, Pinia, keyed v-for, transitions, Nuxt 4 (app directory, pages, layouts, useFetch and useAsyncData keys, $fetch in handlers, server routes, runtime config, useSeoMeta, NuxtImg, middleware), VeeValidate forms, Reka UI and Nuxt UI, testing, vue-tsc, and the traps. Read when the project uses Vue or Nuxt.","https:\u002F\u002Fgithub.com\u002Fenowdev\u002Fenowxcli\u002Fblob\u002Fmain\u002Fcrates\u002Fenowx-core\u002Fskills\u002Fui-stack-vue\u002FSKILL.md",[],[96,154,155,156,157,158,159,160,105,77,161,162,26,163,164,165,166,167,168,21],"vue","stack","ui stack vue","forms","pages","watch","runtime","transitions","fetch","pinia","nuxt","template","server","config","directory"]