Skip to content

Testing

Diego Alfonso edited this page Jan 26, 2026 · 2 revisions

Testing

PrivUtil maintains 80%+ test coverage across backend and frontend.

Quick Test

make test

This runs both backend and frontend tests.

Backend Tests (Go)

Run Tests

make test-backend
# or
go test -tags=manual -cover ./...

View Coverage

go test -tags=manual -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
open coverage.html

Test Structure

internal/api/
└── grpc_server_test.go  # All backend tests

Writing Backend Tests

Use table-driven tests:

func TestMyFunction(t *testing.T) {
    s := NewServer()
    ctx := context.Background()

    tests := []struct {
        name      string
        input     string
        want      string
        wantError bool
    }{
        {"valid", "hello", "HELLO", false},
        {"empty", "", "", true},
    }

    for _, tt := range tests {
        t.Run(tt.name, func(t *testing.T) {
            resp, err := s.MyFunction(ctx, &pb.MyRequest{Input: tt.input})
            if err != nil {
                t.Fatalf("error = %v", err)
            }
            if tt.wantError && resp.Error == "" {
                t.Error("expected error")
            }
            if !tt.wantError && resp.Output != tt.want {
                t.Errorf("got %v, want %v", resp.Output, tt.want)
            }
        })
    }
}

Frontend Tests (Vitest)

Run Tests

make test-frontend
# or
cd web && npm test

Watch Mode

cd web && npm run test:watch

Coverage Report

cd web && npm run test:coverage
# Opens: web/coverage/index.html

Test Structure

web/src/test/
├── setup.ts            # Test setup (jest-dom)
├── Dashboard.test.tsx  # Dashboard component tests
├── ThemeToggle.test.tsx
├── nav.test.ts
└── utils.test.ts

Writing Frontend Tests

import { describe, it, expect } from "vitest";
import { render, screen, fireEvent } from "@testing-library/react";
import { BrowserRouter } from "react-router-dom";
import { MyComponent } from "../components/MyComponent";

describe("MyComponent", () => {
  const renderComponent = () => {
    return render(
      <BrowserRouter>
        <MyComponent />
      </BrowserRouter>,
    );
  };

  it("renders title", () => {
    renderComponent();
    expect(screen.getByText("My Title")).toBeInTheDocument();
  });

  it("handles user input", () => {
    renderComponent();
    const input = screen.getByPlaceholderText("Enter...");
    fireEvent.change(input, { target: { value: "test" } });
    expect(input).toHaveValue("test");
  });
});

Coverage Targets

Area Target Current
Backend (internal/api) 80% 82.3%
Frontend 80% N/A (excludes proto)

CI Integration

Tests run automatically on:

  • Pull requests
  • Push to main branch

See .github/workflows/test.yml for configuration.

Clone this wiki locally