Skip to content

Seed backend endpoint test databases from a snapshot and align main with account#910

Open
tjementum wants to merge 1 commit into
mainfrom
account-test-snapshot-seeding
Open

Seed backend endpoint test databases from a snapshot and align main with account#910
tjementum wants to merge 1 commit into
mainfrom
account-test-snapshot-seeding

Conversation

@tjementum

Copy link
Copy Markdown
Member

Summary & Motivation

Backend endpoint tests recreated the database schema with EnsureCreated() and reran the full DatabaseSeeder on a fresh in-memory SQLite connection for every test. This change seeds the schema and fixtures once into a template database and fills each test's connection with a binary copy through SqliteConnection.BackupDatabase, which is cheaper than recreating the schema and reseeding for every test.

  • The account endpoint, back-office, and external-authentication base tests now restore from a shared seeded template (SeededDatabaseTemplate) instead of calling EnsureCreated() and reseeding per test. The template is seeded once through the real dependency injection graph so Entity Framework interceptors behave as in production, and a lock serializes the binary copies that feed each test.
  • The main test infrastructure is brought to parity with account: a single host shared per test class (MainWebApplicationFactory, with per-test state carried through an AsyncLocal MainTestContext) plus the same snapshot seeding, replacing the previous per-test host rebuild. The main system has no endpoint tests yet, so this establishes the shared pattern for the first one.
  • Across five runs of the full backend suite the average duration drops from about 22.0 seconds to about 20.9 seconds. The gain is modest because the account host was already shared per class, leaving only the per-test schema-create and reseed as headroom.

Checklist

  • I have added tests, or done manual regression tests
  • I have updated the documentation, if necessary

@tjementum tjementum added the Enhancement New feature or request label Jun 22, 2026
@tjementum tjementum self-assigned this Jun 22, 2026
@tjementum tjementum moved this to 🏗 In Progress in Kanban board Jun 22, 2026
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement New feature or request

Projects

Status: 🏗 In Progress

Development

Successfully merging this pull request may close these issues.

1 participant