Skip to content

Commit 817a4a9

Browse files
committed
Create integration-tests.mdx based on issue #267
1 parent 88edbc0 commit 817a4a9

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
---
2+
title: "Integration Tests"
3+
description: "Generate and run integration tests for your SDK"
4+
---
5+
6+
# Integration Tests
7+
8+
Fern can automatically generate integration tests for your SDK to verify that it correctly interacts with your API endpoints. These tests use a mock server to validate request/response handling without requiring a live API environment.
9+
10+
## Supported Languages
11+
12+
Integration tests are currently supported for:
13+
- TypeScript (version 1.2.4 and later)
14+
- C#
15+
16+
Support for additional languages is in development.
17+
18+
## Prerequisites
19+
20+
- Fern CLI (latest version recommended)
21+
- SDK generator version requirements:
22+
- TypeScript: 1.2.4 or later (1.5.0+ recommended)
23+
- C#: Latest version
24+
25+
## Generating Integration Tests
26+
27+
1. Update your generator version in `fern.config.json`:
28+
29+
```json
30+
{
31+
"generators": {
32+
"typescript": "1.5.0"
33+
}
34+
}
35+
```
36+
37+
2. Run the Fern generate command:
38+
39+
```bash
40+
fern generate
41+
```
42+
43+
This will create integration tests in your SDK's test directory.
44+
45+
## Test Structure
46+
47+
The generated tests include:
48+
49+
- Mock server setup
50+
- Request validation
51+
- Response handling verification
52+
- Error case testing
53+
54+
## Running Tests
55+
56+
For TypeScript SDKs:
57+
58+
```bash
59+
npm test
60+
```
61+
62+
For C# SDKs:
63+
64+
```bash
65+
dotnet test
66+
```
67+
68+
<Note>
69+
The mock server is automatically started and stopped as part of the test suite execution.
70+
</Note>
71+
72+
## Custom Tests
73+
74+
While the generated integration tests cover common API interaction patterns, you can also write custom tests to verify specific scenarios:
75+
76+
```typescript
77+
describe('Custom API Tests', () => {
78+
it('should handle specific business logic', async () => {
79+
const client = new YourApiClient();
80+
const response = await client.someEndpoint();
81+
expect(response).toBeDefined();
82+
});
83+
});
84+
```
85+
86+
## Troubleshooting
87+
88+
Common issues and solutions:
89+
90+
- **Tests not generating**: Ensure you're using a supported generator version
91+
- **Mock server errors**: Verify your Fern CLI is up to date
92+
- **Test failures**: Check that your API definition matches the expected request/response patterns
93+
94+
<Note>
95+
If you're using an older version of the Fern CLI, you may need to update it to access the latest generator versions and features.
96+
</Note>
97+
98+
## Best Practices
99+
100+
1. Keep your generator versions up to date
101+
2. Run integration tests as part of your CI/CD pipeline
102+
3. Combine generated tests with custom test cases for comprehensive coverage
103+
4. Use mock server capabilities to test error scenarios
104+
105+
For more detailed information about testing specific API scenarios, refer to the SDK documentation for your chosen language.

0 commit comments

Comments
 (0)