|
| 1 | +--- |
| 2 | +title: "Integration Tests" |
| 3 | +description: "Test your SDK with auto-generated integration tests" |
| 4 | +--- |
| 5 | + |
| 6 | +# Integration Tests |
| 7 | + |
| 8 | +Fern can automatically generate integration tests for your TypeScript SDK to verify that your client behaves correctly against a mock server. This feature helps ensure your SDK works as expected and maintains compatibility with your API specification. |
| 9 | + |
| 10 | +## Supported Generators |
| 11 | + |
| 12 | +Integration test generation is currently supported in: |
| 13 | +- TypeScript SDK Generator (v1.2.4+) |
| 14 | +- C# SDK Generator |
| 15 | + |
| 16 | +<Callout type="info"> |
| 17 | +We recommend using TypeScript SDK Generator v1.5.0 or later for the best experience with integration tests. |
| 18 | +</Callout> |
| 19 | + |
| 20 | +## Getting Started |
| 21 | + |
| 22 | +### Prerequisites |
| 23 | + |
| 24 | +- Fern CLI (latest version) |
| 25 | +- Node.js 16+ |
| 26 | +- npm or yarn |
| 27 | +- TypeScript SDK Generator v1.2.4 or later |
| 28 | + |
| 29 | +### Updating Your Generator Version |
| 30 | + |
| 31 | +To use integration tests, ensure you're using a supported generator version: |
| 32 | + |
| 33 | +```yaml |
| 34 | +generators: |
| 35 | + - name: fernapi/fern-typescript-sdk |
| 36 | + version: 1.5.0 |
| 37 | + output: |
| 38 | + location: local-file-system |
| 39 | + path: ../generated/typescript |
| 40 | +``` |
| 41 | +
|
| 42 | +<Callout type="warning"> |
| 43 | +If you're seeing version 1.0.0 or 1.0.1 selected automatically, update your Fern CLI to the latest version to access newer generator versions. |
| 44 | +</Callout> |
| 45 | +
|
| 46 | +## Test Structure |
| 47 | +
|
| 48 | +When you generate your SDK, Fern automatically creates: |
| 49 | +1. A test directory with the basic test infrastructure |
| 50 | +2. Integration tests based on your API specification |
| 51 | +3. Stubs for custom tests |
| 52 | +
|
| 53 | +The generated tests use a mock server to validate: |
| 54 | +- Request/response handling |
| 55 | +- Parameter serialization |
| 56 | +- Error scenarios |
| 57 | +- Authentication flows |
| 58 | +- API endpoint behavior |
| 59 | +
|
| 60 | +## Running Tests |
| 61 | +
|
| 62 | +To run the integration tests: |
| 63 | +
|
| 64 | +```bash |
| 65 | +npm test |
| 66 | +``` |
| 67 | + |
| 68 | +Or with yarn: |
| 69 | + |
| 70 | +```bash |
| 71 | +yarn test |
| 72 | +``` |
| 73 | + |
| 74 | +## Custom Tests |
| 75 | + |
| 76 | +While the auto-generated tests cover most common scenarios, you can add custom tests for specific use cases: |
| 77 | + |
| 78 | +```typescript |
| 79 | +describe('Custom API Tests', () => { |
| 80 | + it('should handle specific business logic', async () => { |
| 81 | + const client = new YourApiClient(); |
| 82 | + const response = await client.someEndpoint(); |
| 83 | + expect(response).toBeDefined(); |
| 84 | + }); |
| 85 | +}); |
| 86 | +``` |
| 87 | + |
| 88 | +## Best Practices |
| 89 | + |
| 90 | +1. Keep your generator version up to date for the latest testing features |
| 91 | +2. Run tests before publishing SDK updates |
| 92 | +3. Add custom tests for complex business logic |
| 93 | +4. Use the mock server for consistent test behavior |
| 94 | + |
| 95 | +<Callout type="info"> |
| 96 | +Integration test support for additional SDK generators is under development. Check the Fern documentation for updates. |
| 97 | +</Callout> |
0 commit comments