Testing
Testing Strategy
Unit Testing
Setup
npm install --save-dev jest @types/jestTest Structure
// tools/__tests__/search-businesses.test.ts
import { searchBusinesses } from '../search-businesses';
import { AIDPClient } from '@aidp/sdk';
// Mock AIDP client
jest.mock('@aidp/sdk');
describe('search_businesses tool', () => {
let mockClient: jest.Mocked<AIDPClient>;
beforeEach(() => {
mockClient = new AIDPClient({ apiKey: 'test' }) as jest.Mocked<AIDPClient>;
});
afterEach(() => {
jest.clearAllMocks();
});
it('should search for businesses successfully', async () => {
// Arrange
const mockResponse = {
success: true,
data: {
businesses: [{ id: 'biz_1', name: 'Test Business' }],
total: 1,
},
};
mockClient.search.mockResolvedValue(mockResponse);
// Act
const result = await searchBusinesses.handler({
query: 'coffee shops',
location: { lat: 45.5231, lon: -122.6765 },
});
// Assert
expect(result.success).toBe(true);
expect(result.data.businesses).toHaveLength(1);
expect(mockClient.search).toHaveBeenCalledWith({
query: 'coffee shops',
location: { lat: 45.5231, lon: -122.6765, distance: '10km' },
limit: 10,
});
});
it('should handle missing parameters', async () => {
// Act
const result = await searchBusinesses.handler({});
// Assert
expect(result.success).toBe(false);
expect(result.error.code).toBe('INVALID_PARAMETERS');
});
it('should handle API errors', async () => {
// Arrange
mockClient.search.mockRejectedValue(new Error('API Error'));
// Act
const result = await searchBusinesses.handler({
query: 'coffee',
location: { lat: 45.5231, lon: -122.6765 },
});
// Assert
expect(result.success).toBe(false);
expect(result.error.code).toBe('SEARCH_FAILED');
});
});Running Unit Tests
Integration Testing
Setup
Running Integration Tests
End-to-End Testing
Setup
Performance Testing
Using Artillery
Performance Metrics
Security Testing
Authentication Tests
Test Coverage
Measuring Coverage
Coverage Goals
Coverage Report
Continuous Integration
GitHub Actions
Manual Testing
Using cURL
Using Postman
Debugging Tests
Enable Debug Logging
Use Test Debugger
Best Practices
1. Test Isolation
2. Use Test Fixtures
3. Test Edge Cases
4. Test Timeouts
Troubleshooting
Tests Failing Intermittently
Slow Tests
Memory Leaks
Next Steps
Support
Last updated