testing-integration
Integration: API testing Supertest/httpx, test containers, service integration, contract testing Pact
What this skill does
## Purpose
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.
## When to Use
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.
## Key Capabilities
- Perform HTTP API testing with Supertest for Node.js apps, including mocking and assertions.
- Use httpx in Python for asynchronous HTTP requests and integration with databases.
- Manage test containers via Testcontainers to spin up isolated environments (e.g., Docker-based databases).
- Conduct contract testing with Pact to define and verify API provider-consumer agreements.
- Support for service integration testing, such as linking APIs to external services or databases.
## Usage Patterns
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.
## Common Commands/API
- **Supertest (Node.js)**: Use `supertest` to test Express apps. Command: `npm install supertest`. Code snippet:
```javascript
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.
- **httpx (Python)**: For async HTTP testing. Command: `pip install httpx`. Code snippet:
```python
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`).
- **Testcontainers**: Spin up containers for integration. Command: Add to pom.xml or requirements. Code snippet:
```java
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`.
- **Pact (Contract Testing)**: Define and verify contracts. Command: `npm install @pact-foundation/pact` or `pip install pact-python`. Code snippet:
```javascript
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`.
## Integration Notes
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`.
## Error Handling
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.:
```python
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.
## Concrete Usage Examples
1. **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.
2. **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.
## Graph Relationships
- Related to cluster: "testing" (e.g., shares tags with unit-testing skills).
- Connected to skills: "api-development" via integration-test tag for API workflows.
- Links to: "contract-management" through contract-test tag for Pact-based verification.
- Associated with: "database-integration" due to test containers for database testing.
Related in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.