mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 07:47:54 +01:00
* Initial plan * Add 31 parallelizable LineCanvas unit tests Co-authored-by: tig <585482+tig@users.noreply.github.com> * Add 4 parallelizable Ruler unit tests Co-authored-by: tig <585482+tig@users.noreply.github.com> * Complete Category A migration - 35 tests migrated Co-authored-by: tig <585482+tig@users.noreply.github.com> * Remove duplicate tests from UnitTests after migration to Parallelizable Co-authored-by: tig <585482+tig@users.noreply.github.com> * Migrate 6 pure unit tests from ColorPicker and DatePicker to Parallelizable Co-authored-by: tig <585482+tig@users.noreply.github.com> * Fix duplicate test names between UnitTests and Parallelizable Co-authored-by: tig <585482+tig@users.noreply.github.com> * Migrate 11 Label tests to Parallelizable (52 tests total) Co-authored-by: tig <585482+tig@users.noreply.github.com> * Fix documentation: SetupFakeDriver tests CAN be parallelized Co-authored-by: tig <585482+tig@users.noreply.github.com> * Add comprehensive parallelization rules to documentation Co-authored-by: tig <585482+tig@users.noreply.github.com> * Update README and start migrating Button/CheckBox/RadioGroup tests Co-authored-by: tig <585482+tig@users.noreply.github.com> * Remove duplicate Button tests from UnitTests Co-authored-by: tig <585482+tig@users.noreply.github.com> * Migrate 5 CheckBox unit tests to Parallelizable (27 with Theory expansion) Co-authored-by: tig <585482+tig@users.noreply.github.com> * Migrate 4 more CheckBox tests to Parallelizable (67 tests total, 9,478 passing) Co-authored-by: tig <585482+tig@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: tig <585482+tig@users.noreply.github.com> Co-authored-by: Tig <tig@users.noreply.github.com>
4.1 KiB
4.1 KiB
UnitTests.Parallelizable
This project contains unit tests that can run in parallel without interference. Tests here must not depend on global state or static Application infrastructure.
Migration Rules
Tests CAN be parallelized if they:
- ✅ Test properties, constructors, and basic operations
- ✅ Use
[SetupFakeDriver]without Application statics - ✅ Call
View.Draw(),LayoutAndDraw()without Application statics - ✅ Verify visual output with
DriverAssert(when using[SetupFakeDriver]) - ✅ Create View hierarchies without
Application.Top - ✅ Test events and behavior without global state
- ✅ Use
View.BeginInit()/View.EndInit()for initialization
Tests CANNOT be parallelized if they:
- ❌ Use
[AutoInitShutdown]- requiresApplication.Init/Shutdownwhich creates global state - ❌ Set
Application.Driver(global singleton) - ❌ Call
Application.Init(),Application.Run/Run<T>(), orApplication.Begin() - ❌ Modify
ConfigurationManagerglobal state (Enable/Load/Apply/Disable) - ❌ Modify static properties like
Key.Separator,CultureInfo.CurrentCulture, etc. - ❌ Use
Application.Top,Application.Driver,Application.MainLoop, orApplication.Navigation - ❌ Are true integration tests that test multiple components working together
Important Notes
- Many tests in
UnitTestsblindly use the above patterns when they don't actually need them - These tests CAN be rewritten to remove unnecessary dependencies and migrated here
- Many tests APPEAR to be integration tests but are just poorly written and cover multiple surface areas - these can be split into focused unit tests
- When in doubt, analyze if the test truly needs global state or can be refactored
How to Migrate Tests
- Identify tests in
UnitTeststhat don't actually need Application statics - Rewrite tests to remove
[AutoInitShutdown],Application.Begin(), etc. if not needed - Move the test to the equivalent file in
UnitTests.Parallelizable - Delete the old test from
UnitTeststo avoid duplicates - Verify no duplicate test names exist (CI will check this)
- Test to ensure the migrated test passes
Example Migrations
Simple Property Test (no changes needed)
// Before (in UnitTests)
[Fact]
public void Constructor_Sets_Defaults ()
{
var view = new Button ();
Assert.Empty (view.Text);
}
// After (in UnitTests.Parallelizable) - just move it!
[Fact]
public void Constructor_Sets_Defaults ()
{
var view = new Button ();
Assert.Empty (view.Text);
}
Remove Unnecessary [SetupFakeDriver]
// Before (in UnitTests)
[Fact]
[SetupFakeDriver]
public void Event_Fires_When_Property_Changes ()
{
var view = new Button ();
var fired = false;
view.TextChanged += (s, e) => fired = true;
view.Text = "Hello";
Assert.True (fired);
}
// After (in UnitTests.Parallelizable) - remove attribute!
[Fact]
public void Event_Fires_When_Property_Changes ()
{
var view = new Button ();
var fired = false;
view.TextChanged += (s, e) => fired = true;
view.Text = "Hello";
Assert.True (fired);
}
Replace Application.Begin with View Initialization
// Before (in UnitTests)
[Fact]
[AutoInitShutdown]
public void Focus_Test ()
{
var view = new Button ();
var top = new Toplevel ();
top.Add (view);
Application.Begin (top);
view.SetFocus ();
Assert.True (view.HasFocus);
top.Dispose ();
}
// After (in UnitTests.Parallelizable) - use BeginInit/EndInit!
[Fact]
public void Focus_Test ()
{
var superView = new View ();
var view = new Button ();
superView.Add (view);
superView.BeginInit ();
superView.EndInit ();
view.SetFocus ();
Assert.True (view.HasFocus);
}
Running Tests
Tests in this project run in parallel automatically. To run them:
dotnet test Tests/UnitTestsParallelizable/UnitTests.Parallelizable.csproj
See Also
- Category A Migration Summary - Detailed analysis and migration guidelines
- .NET Unit Testing Best Practices