IMVEEDev Portal

Test Strategy

Overview of the test pyramid, coverage goals and best practices for SOCSuite.


Test Pyramid

        E2E (Playwright)
       ─────────────────────
      │ Critical workflows  │  10% — Safety-critical
      └─────────────────────┘

     API Contract Tests
    ──────────────────────────
   │  HTTP + JSON Schema     │  15% — All public endpoints
   └─────────────────────────┘

    Integration Tests
   ──────────────────────────
  │ Testcontainers + Redis   │  25% — Component interaction
  └──────────────────────────┘

Unit Tests (Service + Repository)
──────────────────────────────────────────
│ sqlmock + Testify + Table-Driven Tests │  50% — Business logic
└─────────────────────────────────────────┘

Coverage Goals

LevelMinimumTarget
Unit tests (backend)80%85%
Integration tests60% critical services75%
API contract tests90% of all endpoints100%
Frontend (React)75%80%

Unit Tests

Technology: Testify + sqlmock + Table-Driven Tests

func TestAlertService_GetByID(t *testing.T) {
    tests := []struct {
        name    string
        id      string
        want    *domain.Alert
        wantErr error
    }{
        {"valid id", "uuid-1", &domain.Alert{ID: "uuid-1"}, nil},
        {"not found", "unknown", nil, domain.ErrNotFound},
        {"empty id", "", nil, domain.ErrValidation},
    }

    for _, tt := range tests {
        t.Run(tt.name, func(t *testing.T) {
            got, err := svc.GetByID(ctx, tt.id)
            assert.ErrorIs(t, err, tt.wantErr)
            assert.Equal(t, tt.want, got)
        })
    }
}
go test ./internal/...
go test -cover ./internal/...

Integration Tests

Technology: Testcontainers (PostgreSQL 16) — start the container once in TestMain, reuse for all tests. TRUNCATE CASCADE between tests.

:::warn [No SQLite as PostgreSQL substitute] PostgreSQL-specific features (JSONB, full-text search, transactions) are handled differently. :::

//go:build integration

func TestMain(m *testing.M) {
    container := startPostgreSQLContainer()
    defer container.Terminate(ctx)
    applySchema(container.ConnectionString(), "../../02_Initialisation/initdb/")
    os.Exit(m.Run())
}
go test -tags=integration ./tests/integration/...
go test -tags=integration -race ./tests/integration/...

E2E Tests

Technology: Playwright (Chromium, Firefox, WebKit)

:::info [Essential for a SOC platform] A failed incident response is a security risk. :::

Critical scenarios (mandatory):

ScenarioDescription
Incident ResponseAlert → Case → Playbook → Containment → Closure
RBAC EnforcementViewer cannot edit a case
Multi-User Collaboration2 analysts, real-time updates via WebSocket
Evidence Chain-of-CustodySHA256 verified, transfer logged
Auth & SessionLogin → Token refresh → Logout
Error RecoveryDB down, OpenSearch down, agent offline
pnpm test:e2e
pnpm test:e2e --headed          # Visible browser
pnpm test:e2e --reporter=html   # HTML report

Frontend Tests

Technology: Vitest + React Testing Library + MSW v2

test("shows alert count", async () => {
  render(<AlertDashboard />);
  expect(await screen.findByText("5 Alerts")).toBeInTheDocument();
});
pnpm test:unit          # Unit tests
pnpm test:coverage      # Coverage report

Quality Gates

PhaseChecksLimit
pre-commitUnit ≥80%, gosec HIGH<3 min
pre-mergego test -race, integration, govulncheck<5 min
post-mergeE2E, OWASP ZAP, trivy<10 min

Test Structure

apps/api/
├── internal/
│   ├── service/
│   │   └── *_test.go           ← Unit tests (sqlmock)
│   └── repository/
│       └── *_test.go           ← Unit tests (sqlmock)
└── tests/
    ├── integration/            ← Testcontainers (build tag: integration)
    ├── api/                    ← API contract tests
    └── testutil/               ← Shared test helpers

apps/web/
└── src/
    └── **/*.test.ts(x)         ← Vitest unit tests
    tests/
    └── e2e/                    ← Playwright E2E

Best Practices

:::info [DO]

  • Table-driven tests for validation logic
  • t.Parallel() for independent unit tests
  • TRUNCATE CASCADE instead of DELETE in integration tests
  • Test names: TestService_Method_Scenario :::

:::error [DON'T]

  • No time.Sleep() → use waitFor / Testify with timeout
  • No dependencies between tests
  • No SQLite as a PostgreSQL substitute
  • No production secrets in tests :::

Further Reading

On this page