Skip to content

refactor(tests): replace complex TestCaseSource objects with enum-based provider + factory#320

Merged
DevD4v3 merged 1 commit intodevfrom
patch-1
Nov 28, 2025
Merged

refactor(tests): replace complex TestCaseSource objects with enum-based provider + factory#320
DevD4v3 merged 1 commit intodevfrom
patch-1

Conversation

@DevD4v3
Copy link
Owner

@DevD4v3 DevD4v3 commented Nov 28, 2025

NUnit occasionally failed in GitHub Actions with a NullReferenceException in CreatePlayer tests when using RepositoryManagerTestCases. The root cause was NUnit’s internal cloning/serialization behavior: complex objects returned by
TestCaseSource can be cloned using GetUninitializedObject, bypassing their constructors and producing partially-initialized instances (e.g., DI-managed repositories set to null).
This happens before the test lifecycle begins and outside the test context, which explains why failures were intermittent and
only reproduced in CI.

This refactor replaces complex test case objects with a simple enum (DatabaseProvider). IRepositoryManager instances are now created inside the test via a dedicated factory, guaranteeing:

  • Objects are instantiated within the test’s lifecycle.
  • NUnit no longer clones or serializes DI-based classes.
  • Stable behavior across local runs and GitHub Actions.
  • Proper debugging, since constructors now execute predictably.
  • Fully isolated tests with no pre-initialized or shared state.

All tests were updated to use the new enum-based provider and factory pattern.

@DevD4v3 DevD4v3 merged commit 594648a into dev Nov 28, 2025
2 checks passed
@DevD4v3 DevD4v3 deleted the patch-1 branch November 28, 2025 14:20
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.

1 participant