Quality Assurance
Testing Guide
Best practices for testing your JustKalm integration. From unit tests to CI/CD pipelines, we've got you covered.
Testing Strategy
Unit Tests
Mock the JustKalm client to test your business logic in isolation. Fast, reliable, no API calls.
~5ms per test
Integration Tests
Use test mode API keys to verify your integration works end-to-end with real API calls.
~200ms per test
E2E Tests
Full end-to-end tests with your UI. Use test mode for predictable results.
~2s per test
Code Examples
Python Unit Test
import pytest
from unittest.mock import patch, MagicMock
from justkalm import JustKalm
class TestValuation:
@patch('justkalm.client.requests.post')
def test_valuate_returns_price_range(self, mock_post):
# Arrange
mock_response = MagicMock()
mock_response.json.return_value = {
"price_min": 150,
"price_max": 250,
"confidence": 0.92,
"currency": "USD"
}
mock_response.status_code = 200
mock_post.return_value = mock_response
client = JustKalm(api_key="jk_test_xxx")
# Act
result = client.valuate(url="https://example.com/item")
# Assert
assert result.price_min == 150
assert result.price_max == 250
assert result.confidence > 0.9Test Fixtures
JustKalm provides special test URLs that return predictable responses for testing:
| Test URL | Response | Use Case |
|---|---|---|
| test://success | 200 OK with valuation | Happy path testing |
| test://not-found | 404 Not Found | Error handling |
| test://rate-limit | 429 Too Many Requests | Rate limit handling |
| test://timeout | Connection timeout (30s) | Timeout handling |
| test://invalid-response | 500 Server Error | Server error handling |
| test://slow | 200 OK after 5s delay | Slow response handling |
| test://partial | 200 with partial data | Missing fields |
Best Practices
Follow these steps to set up testing:
- 1Get a test API key from the dashboard
- 2Set JUSTKALM_API_KEY environment variable
- 3Install testing framework (pytest, vitest, jest)
- 4Create test fixtures for common responses
- 5Run unit tests first, then integration
What to Test
Should Test
- API response parsing and mapping
- Error handling for all error codes
- Retry logic and backoff behavior
- Webhook signature verification
- Rate limit handling
- Timeout behavior
- Cache invalidation
- Business logic using valuations
Can Skip (SDK Handles)
- HTTP connection handling
- Request serialization
- Response deserialization
- Authentication header injection
- Automatic retries (already tested)
- Keep-alive connection pooling
- Request/response logging
Need Help With Testing?
Our team is here to help you set up a robust testing strategy.