|
|
2 weeks ago | |
|---|---|---|
| .. | ||
| Application | 2 weeks ago | |
| Configuration | 2 weeks ago | |
| Drawing | 3 weeks ago | |
| Drivers | 2 weeks ago | |
| FileServices | 1 month ago | |
| Input | 2 weeks ago | |
| Resources | 1 month ago | |
| Text | 2 weeks ago | |
| View | 2 weeks ago | |
| Views | 2 weeks ago | |
| AssemblyInfo.cs | 6 months ago | |
| LocalPackagesTests.cs | 1 month ago | |
| README.md | 2 weeks ago | |
| TestDateAttribute.cs | 2 weeks ago | |
| TestSetup.cs | 2 weeks ago | |
| UnitTests.Parallelizable.csproj | 3 weeks ago | |
| UnitTests.Parallelizable.csproj.DotSettings | 9 months ago | |
| runsettings.coverage.xml | 1 month ago | |
| runsettings.xml | 1 month ago | |
| xunit.runner.json | 2 weeks ago | |
This project contains unit tests that can run in parallel without interference. Tests here must not depend on global state or static Application infrastructure.
[SetupFakeDriver] without Application staticsView.Draw(), LayoutAndDraw() without Application staticsDriverAssert (when using [SetupFakeDriver])Application.TopView.BeginInit() / View.EndInit() for initialization[AutoInitShutdown] or [SetupFakeApplication]- requires Application.Init/Shutdown which creates global stateApplication.Driver (global singleton)Application.Init(), Application.Run/Run<T>(), or Application.Begin()ConfigurationManager (Enable/Load/Apply/Disable)ConfigurationManager including ThemeManager and SchemeManager - these rely on global stateKey.Separator, CultureInfo.CurrentCulture, etc.Dialog.DefaultButtonAlignment) or any static fields/properties - these are shared across all parallel testsUnitTests blindly use the above patterns when they don't actually need themUnitTests that don't actually need Application statics[AutoInitShutdown] or [SetupFakeApplication], Application.Begin(), etc. if not neededUnitTests.ParallelizableUnitTests to avoid duplicates// 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);
}
// Before (in UnitTests)
[Fact]
[SetupFakeApplication]
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);
}
// 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);
}
Tests in this project run in parallel automatically. To run them:
dotnet test Tests/UnitTestsParallelizable/UnitTests.Parallelizable.csproj