GraphicsTestCollection.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132
  1. namespace MonoGame.Extended.Tests.Fixtures;
  2. /// <summary>
  3. /// Defines a shared test collection for graphics tests to prevent SDL initialization conflicts.
  4. ///
  5. /// IMPORTANT: This solves the critical issue where multiple graphics test classes would crash
  6. /// when run together due to SDL trying to initialize multiple times simultaneously.
  7. ///
  8. /// The problem:
  9. /// - Each test class with IClassFixture<GameFixture> creates its own GameFixture instance
  10. /// - Each GameFixture creates a new MonoGame Game instance
  11. /// - Multiple Game instances try to initialize SDL at the same time
  12. /// - This causes a fatal 0xC0000005 error in Sdl.Init()
  13. ///
  14. /// The solution:
  15. /// - Use ICollectionFixture instead of IClassFixture
  16. /// - All graphics test classes use [Collection("Graphics")] attribute
  17. /// - This ensures only ONE GameFixture instance is shared across all graphics tests
  18. /// - SDL is initialized only once, preventing conflicts
  19. ///
  20. /// Usage:
  21. /// - Mark any test class that needs graphics with [Collection("Graphics")]
  22. /// - The test class constructor receives GameFixture as a parameter
  23. /// - All tests in the collection share the same GameFixture instance
  24. /// </summary>
  25. [CollectionDefinition("GraphicsTest")]
  26. public class GraphicsTestCollection : ICollectionFixture<GraphicsTestFixture>
  27. {
  28. // This class has no code, and is never created. Its purpose is simply
  29. // to be the place to apply [CollectionDefinition] and all the
  30. // ICollectionFixture<> interfaces.
  31. }