SDK Documentation

Official SDKs for popular programming languages

Node.js SDK

Installation

npm install aitotest-sdk
# or
yarn add aitotest-sdk

Quick Start

const AIToTest = require('aitotest-sdk');

const client = new AIToTest({
  apiKey: 'your_api_key',
  project: 'your_project_id'
});

// Generate tests
const tests = await client.generateTests({
  files: ['src/utils.js'],
  framework: 'jest'
});

// Run tests
const results = await client.runTests({
  testFiles: tests.files,
  coverage: true
});

Python SDK

Installation

pip install aitotest
# or
poetry add aitotest

Quick Start

from aitotest import Client

client = Client(
    api_key='your_api_key',
    project='your_project_id'
)

# Generate tests
tests = client.generate_tests(
    files=['tests/test_utils.py'],
    framework='pytest'
)

# Run tests
results = client.run_tests(
    test_files=tests.files,
    coverage=True
)

Java SDK

Installation

<!-- Maven -->
<dependency>
    <groupId>com.aitotest</groupId>
    <artifactId>sdk</artifactId>
    <version>1.0.0</version>
</dependency>

<!-- Gradle -->
implementation 'com.aitotest:sdk:1.0.0'

Quick Start

import com.aitotest.Client;

Client client = Client.builder()
    .apiKey("your_api_key")
    .project("your_project_id")
    .build();

// Generate tests
TestGeneration tests = client.generateTests(TestGenerationRequest.builder()
    .files(Arrays.asList("src/test/java/UtilsTest.java"))
    .framework("junit5")
    .build());

// Run tests
TestResults results = client.runTests(TestRunRequest.builder()
    .testFiles(tests.getFiles())
    .coverage(true)
    .build());

Common Features

Test Generation

  • File analysis
  • Framework detection
  • Custom templates
  • Coverage settings

Test Execution

  • Parallel running
  • Coverage reports
  • Custom runners
  • Environment config

Reporting

  • Results analysis
  • Coverage metrics
  • Custom formatters
  • Export options

Advanced Usage

Custom Test Templates

// Node.js example
const template = {
  name: 'custom',
  generate: (fn) => `
    describe('${fn.name}', () => {
      beforeEach(() => {
        // Custom setup
      });

      it('should handle custom case', () => {
        // Custom test logic
      });
    });
  `
};

client.setTemplate(template);

Error Handling

Try-Catch Pattern

try {
  const results = await client.runTests({
    testFiles: ['test.js']
  });
} catch (error) {
  if (error instanceof AIToTestError) {
    console.error(error.message);
    console.error(error.code);
  }
}

Error Types

  • ValidationError
  • AuthenticationError
  • RateLimitError
  • APIError

Best Practices

Configuration

  • Use environment variables
  • Implement retry logic
  • Set appropriate timeouts
  • Cache API responses

Performance

  • Batch operations
  • Use connection pooling
  • Implement caching
  • Handle rate limits