# API Sdk Unit Tests

> Tests generated API SDKs: unit tests for clients, mock-server integration tests, generated code quality gates, and regression suites. Use when working with sdk unit tests, integration tests or when the user mentions sdk unit tests, integration tests.

- Skill: `opknock/api-sdk-unit-tests` (Agent Skill)
- Install (CLI): `npx get-skill add opknock/api-sdk-unit-tests`
- Raw SKILL.md: https://api.skillmd.com/api/skills/opknock/api-sdk-unit-tests/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Integrations & APIs
- License: MIT
- Author: OpKnock (https://skillmd.com/u/opknock)
- Updated: 2026-11-23
- Page: https://skillmd.com/skills/opknock/api-sdk-unit-tests

---


Tests generated API SDKs: unit tests for clients, mock-server integration tests, generated code quality gates, and regression suites.

## Agentic Workflow: Read -> Reason -> Act (api-sdk-unit-tests)

You are **Api Sdk Unit Tests** (backend) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.

### 1. Read — backend context for `api-sdk-unit-tests`
- Domain: Tests generated API SDKs: unit tests for clients, mock-server integration tests, generated code quality gates, and regression suites.
- **sdk-unit-tests**: Write unit tests for SDK client code — `npm install vitest`
- **integration-tests**: Run SDKs against a live mock server — `npx @stoplight/prism-cli mock openapi.yaml -p 4010 &`
- Check `knowledge` and `prerequisites: openapi-generator, node.js, python`

### 2. Reason — think for `api-sdk-unit-tests`
- For `sdk-unit-tests`: Write unit tests for SDK client code — decide which checks to run
- For `integration-tests`: Run SDKs against a live mock server — decide which checks to run
- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs

### 3. Act — execute with `api-sdk-unit-tests` tools
- Tools: `Glob`, `Grep`, `Read`, `Bash`, `Npx` (see frontmatter `tools`/`allowed-tools`)
- Use `safe_path` for any write; record evidence (paths, checksums)
- Fingerprint: `api-sdk-unit-tests:bd36217c`

# API SDK Engineer v2 - Testing

SDK testing and validation.

## What This Skill Does
- Unit-tests client behavior with mocks
- Integration-tests against mock servers
- Gates SDK quality in CI

## When to Use
- Verifying generated clients
- Catching SDK regressions
- Testing error paths

## Real Commands

```bash
npm install vitest
npx vitest run tests/sdk.test.ts
npx @stoplight/prism-cli mock openapi.yaml -p 4010 &
node -e "const sdk=require('./sdk'); sdk.defaultClient.basePath='http://localhost:4010'; sdk.getUsers().then(r=>console.log(r.data.length))"
```

## Test Pattern

```ts
import nock from 'nock';
import { UsersApi } from '../sdk';

test('lists users', async () => {
  nock('https://api.example.com').get('/users').reply(200, [{ id: 1 }]);
  const api = new UsersApi();
  const res = await api.getUsers();
  expect(res.data).toHaveLength(1);
});
```

## Testing
- Cover success, 4xx, and 5xx paths
- Test pagination and auth headers
- Run coverage thresholds in CI

## Best Practices
- Keep tests independent of live APIs
- Test through the public SDK surface
- Regenerate mocks when specs change

## Capabilities

### sdk-unit-tests
Write unit tests for SDK client code

**Parameters:**
- `test-file` (string): Test file path
- `mock-target` (string): URL intercepted by nock
- `coverage` (boolean): Collect coverage

**Commands:**
- `npm install vitest`
- `npx vitest run tests/sdk.test.ts`
- `npx vitest run --coverage`
- `npm install nock`
- `node -e "const nock=require('nock'); nock('http://localhost:8080').get('/users').reply(200,[{id:1}]); fetch('https://api.example.com/users').then(r=>r.json()).then(console.log)"`

**Examples:**
- nock intercepts HTTP for client tests
- vitest run executes the SDK test suite
- --coverage reports branch coverage

### integration-tests
Run SDKs against a live mock server

**Commands:**
- `npx @stoplight/prism-cli mock openapi.yaml -p 4010 &`
- `node -e "const sdk=require('./sdk'); sdk.defaultClient.basePath='http://localhost:4010'; sdk.getUsers().then(r=>console.log(r.data.length))"`
- `npm test`
- `npx vitest run`

**Examples:**
- -cli --help
- -api --help

## References
- [Vitest Docs](https://vitest.dev/guide/)
- [nock Docs](https://github.com/nock/nock)

