Skip to content

Don't use migrations for all tests, add test runner parallelism - #5667

Open
rbev wants to merge 2 commits into
masterfrom
rhys/test-migrations
Open

Don't use migrations for all tests, add test runner parallelism#5667
rbev wants to merge 2 commits into
masterfrom
rhys/test-migrations

Conversation

@rbev

@rbev rbev commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

This pull request introduces improvements to the test infrastructure for the persistence layer, focusing on parallelization, database setup, and migration testing. The main changes include enabling parallel test execution, adjusting database initialization logic for test contexts, and adding a new test to verify that database migrations can be applied successfully.

Test infrastructure improvements:

  • Enabled parallel execution of NUnit tests and set the level of parallelism to 4 in both SqlServer and PostgreSql test projects by adding NUnitSettings.cs files.
  • Changed the database initialization in PersistenceTestsContext for both SqlServer and PostgreSql to use EnsureCreatedAsync instead of MigrateAsync, simplifying test database setup. [1] [2]

Database migration testing:

  • Added a new test class DbMigrationsTests with a test to verify that IDatabaseMigrator.ApplyMigrations() runs successfully, ensuring migrations are tested independently.

Code organization:

  • Updated the namespace in EFCoreExtensionMethodTests.cs to match the rest of the test suite for consistency.

Comment on lines +11 to +18
public async Task ApplyMigrations_runs_successfully()
{
var ctx = new PersistenceTestsContext();
var hostBuilder = new HostApplicationBuilder();
await ctx.Setup(hostBuilder);
var host = hostBuilder.Build();
await host.Services.GetRequiredService<IDatabaseMigrator>().ApplyMigrations();
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this runs the migrations in isolation, so yes we are testing that the migration code is working but not necessarily that when utilized in the tests is working

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've had second thoughts about not running the migrations in every test, if there's any custom sql run during the migrations we will end up with a different database (e.g. creating full text indexes)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants