skills/testing/testing-integration/SKILL.md
Integration: API testing Supertest/httpx, test containers, service integration, contract testing Pact
npx skillsauth add alphaonedev/openclaw-graph testing-integrationInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
This skill facilitates integration testing for APIs and services, focusing on tools like Supertest (Node.js), httpx (Python), Testcontainers for managing test environments, and Pact for contract testing. It ensures end-to-end verification of service interactions, database integrations, and API contracts.
Use this skill when verifying API endpoints in a real environment, testing service integrations (e.g., with databases or external services), running containerized tests, or enforcing contracts between microservices. Apply it in CI/CD pipelines for regression testing or when mocking dependencies is insufficient.
To use this skill, first install required dependencies (e.g., via npm or pip). Set up test files in your project, configure environments with variables like $API_BASE_URL, and run tests using a test runner. For API tests, structure code to send requests and assert responses. For contract testing, define pacts in separate files and verify them against providers. Always isolate tests with containers to avoid side effects. Example pattern: Import the tool, define a test function, send requests, and handle assertions within 2-3 lines.
supertest to test Express apps. Command: npm install supertest. Code snippet:
const request = require('supertest');
const app = require('./app');
request(app).get('/api/users').expect(200);
CLI flag: Run with npx jest --runInBand for sequential tests.pip install httpx. Code snippet:
import httpx
response = httpx.get('http://example.com/api/data', headers={'Authorization': f'Bearer {os.environ.get("API_KEY")}'}).json()
assert response['status'] == 'success'
API endpoint: Pass URLs like https://api.service.com/endpoint with query params (e.g., ?limit=10).GenericContainer container = new GenericContainer("postgres:13").withExposedPorts(5432);
container.start();
String jdbcUrl = container.getJdbcUrl();
Config format: Use Docker image specs in YAML, e.g., image: postgres:13 with env vars like $DB_PASSWORD.npm install @pact-foundation/pact or pip install pact-python. Code snippet:
const { Pact } = require('@pact-foundation/pact');
const pact = new Pact({ consumer: 'MyConsumer', provider: 'MyProvider' });
pact.addInteraction({ state: 'default', uponReceiving: 'a request' });
API: Use endpoints like /pacts/provider/MyProvider/consumer/MyConsumer/verification for verification, with auth via $PACT_BROKER_TOKEN.Integrate this skill by adding it to your build tools: For Node.js, include in Jest or Mocha configs; for Python, use pytest fixtures. Set env vars like $DATABASE_URL for database connections or $SERVICE_API_KEY for authenticated requests. For container integration, ensure Docker is installed and use Testcontainers to link services (e.g., expose ports via withExposedPorts(8080)). When combining with Pact, publish pacts to a broker (e.g., via pact-broker publish --broker-url=$PACT_BROKER_URL). Config format: Use JSON for Pact files, e.g., { "interactions": [...] }, and ensure compatibility with CI tools like GitHub Actions by adding steps like run: docker-compose up -d.
Handle errors by wrapping requests in try-catch blocks. For Supertest, check response status and body: e.g., if .expect(200) fails, log the error with console.error(response.error). In httpx, catch httpx.HTTPError for network issues, e.g.:
try:
response = httpx.get(url)
response.raise_for_status()
except httpx.HTTPError as e:
print(f"Error: {e} - Check $API_BASE_URL")
For Testcontainers, verify container startup with container.isRunning() before tests. In Pact, use pact.verify() and handle mismatches by reviewing pact files. Common patterns: Use env vars for retries (e.g., $RETRY_COUNT=3) and log detailed errors with stack traces.
API Integration Test with Supertest: To test a user endpoint in a Node.js app with a database, first set $DB_URL=postgres://user:pass@localhost:5432/db. Write a test file: Import Supertest, send a GET request, and assert the response. Run with npx jest tests/integration.test.js. This verifies the API connects to the database and returns data.
Contract Test with Pact: For a consumer-provider setup, define a pact in a file (e.g., pacts/my-pact.json) with interactions. Use pact.verify() against the provider endpoint (e.g., http://provider.com), passing $PACT_BROKER_TOKEN. Run via npx pact-verifier --provider-base-url=$PROVIDER_URL. This ensures the consumer's expectations match the provider's implementation.
tools
Root web development: project structure, tooling selection, deployment decisions
development
WebAssembly: Rust/Go/C to WASM, wasm-bindgen, Emscripten, WASM Component Model
development
Vue 3: Composition API script setup, Pinia, Vue Router 4, SFCs, Vite, Nuxt 3
tools
Tailwind CSS 4: utility classes, config, JIT, arbitrary values, darkMode, plugins, shadcn/ui