Skip to main content

Overview

Comprehensive testing ensures code quality and reliability across the Olis monorepo.

Running Tests

# Run all tests
pnpm test

# Run tests for specific app
pnpm nx test electron-client
pnpm nx test api-server

# Watch mode
pnpm nx test electron-client --watch

# With coverage
pnpm nx test --coverage

Test Types

Unit Tests

Test individual functions and components in isolation

Integration Tests

Test interactions between components and services

E2E Tests

Test complete user workflows from start to finish

API Tests

Test API endpoints and responses

Electron Client Testing

Unit Tests with Jest

// src/components/ChatMessage.test.tsx
import { render, screen } from '@testing-library/react'
import ChatMessage from './ChatMessage'

describe('ChatMessage', () => {
  it('renders message text', () => {
    render(<ChatMessage text="Hello" sender="user" />)
    expect(screen.getByText('Hello')).toBeInTheDocument()
  })

  it('applies correct styling for user messages', () => {
    const { container } = render(
      <ChatMessage text="Hello" sender="user" />
    )
    expect(container.firstChild).toHaveClass('user-message')
  })
})

E2E Tests with Playwright

// e2e/chat.spec.ts
import { test, expect } from '@playwright/test'

test('can send a chat message', async ({ page }) => {
  await page.goto('http://localhost:3000')

  await page.fill('[data-testid="chat-input"]', 'What is Olis?')
  await page.click('[data-testid="send-button"]')

  await expect(page.locator('[data-testid="chat-message"]')).toContainText('What is Olis?')
})

API Server Testing

pytest Integration Tests

# tests/integration_tests/test_fastapi.py
import pytest
from fastapi.testclient import TestClient
from main import app

client = TestClient(app)

def test_health_endpoint():
    response = client.get("/health")
    assert response.status_code == 200
    assert response.json()["status"] == "healthy"

def test_chat_endpoint():
    response = client.post(
        "/api/chat",
        json={
            "message": "Hello",
            "sessionId": "test-session"
        }
    )
    assert response.status_code == 200
    assert "response" in response.json()

@pytest.mark.asyncio
async def test_rag_pipeline():
    # Test document ingestion
    # Test retrieval
    # Test generation
    pass

Best Practices

  • Small, focused functions
  • Avoid side effects
  • Use dependency injection
  • Mock external dependencies
  • Aim for 80%+ coverage
  • Focus on critical paths
  • Don’t test implementation details
  • Test behavior, not code
  • Mirror source structure
  • Group related tests
  • Clear test names
  • Arrange-Act-Assert pattern

Next Steps