Skip to content

Commit

Permalink
Add option to order tests by name (#3796)
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink authored Sep 10, 2024
1 parent 62659f7 commit 4959941
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,11 @@ private void ExecuteTestsWithTestRunner(
bool hasAnyRunnableTests = false;
var fixtureTests = new List<TestCase>();

foreach (TestCase currentTest in tests)
IEnumerable<TestCase> orderedTests = MSTestSettings.CurrentSettings.OrderTestsByNameInClass
? tests.OrderBy(t => t.GetManagedType()).ThenBy(t => t.GetManagedMethod())
: tests;

foreach (TestCase currentTest in orderedTests)
{
_testRunCancellationToken?.ThrowIfCancellationRequested();

Expand Down
52 changes: 37 additions & 15 deletions src/Adapter/MSTest.TestAdapter/MSTestSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public MSTestSettings()
TestCleanupTimeout = 0;
TreatClassAndAssemblyCleanupWarningsAsErrors = false;
CooperativeCancellationTimeout = false;
OrderTestsByNameInClass = false;
}

/// <summary>
Expand Down Expand Up @@ -204,6 +205,11 @@ public static RunConfigurationSettings RunConfigurationSettings
/// </summary>
internal bool CooperativeCancellationTimeout { get; private set; }

/// <summary>
/// Gets a value indicating whether tests should be ordered by name in the class.
/// </summary>
internal bool OrderTestsByNameInClass { get; private set; }

/// <summary>
/// Populate settings based on existing settings object.
/// </summary>
Expand All @@ -215,28 +221,29 @@ public static void PopulateSettings(MSTestSettings settings)
return;
}

CurrentSettings.AssemblyCleanupTimeout = settings.AssemblyCleanupTimeout;
CurrentSettings.AssemblyInitializeTimeout = settings.AssemblyInitializeTimeout;
CurrentSettings.CaptureDebugTraces = settings.CaptureDebugTraces;
CurrentSettings.ClassCleanupLifecycle = settings.ClassCleanupLifecycle;
CurrentSettings.ClassCleanupTimeout = settings.ClassCleanupTimeout;
CurrentSettings.ClassInitializeTimeout = settings.ClassInitializeTimeout;
CurrentSettings.ConsiderEmptyDataSourceAsInconclusive = settings.ConsiderEmptyDataSourceAsInconclusive;
CurrentSettings.ConsiderFixturesAsSpecialTests = settings.ConsiderFixturesAsSpecialTests;
CurrentSettings.CooperativeCancellationTimeout = settings.CooperativeCancellationTimeout;
CurrentSettings.DisableParallelization = settings.DisableParallelization;
CurrentSettings.EnableBaseClassTestMethodsFromOtherAssemblies = settings.EnableBaseClassTestMethodsFromOtherAssemblies;
CurrentSettings.ForcedLegacyMode = settings.ForcedLegacyMode;
CurrentSettings.TestSettingsFile = settings.TestSettingsFile;
CurrentSettings.MapInconclusiveToFailed = settings.MapInconclusiveToFailed;
CurrentSettings.MapNotRunnableToFailed = settings.MapNotRunnableToFailed;
CurrentSettings.TreatDiscoveryWarningsAsErrors = settings.TreatDiscoveryWarningsAsErrors;
CurrentSettings.EnableBaseClassTestMethodsFromOtherAssemblies = settings.EnableBaseClassTestMethodsFromOtherAssemblies;
CurrentSettings.ClassCleanupLifecycle = settings.ClassCleanupLifecycle;
CurrentSettings.ParallelizationWorkers = settings.ParallelizationWorkers;
CurrentSettings.OrderTestsByNameInClass = settings.OrderTestsByNameInClass;
CurrentSettings.ParallelizationScope = settings.ParallelizationScope;
CurrentSettings.DisableParallelization = settings.DisableParallelization;
CurrentSettings.ParallelizationWorkers = settings.ParallelizationWorkers;
CurrentSettings.TestCleanupTimeout = settings.TestCleanupTimeout;
CurrentSettings.TestInitializeTimeout = settings.TestInitializeTimeout;
CurrentSettings.TestSettingsFile = settings.TestSettingsFile;
CurrentSettings.TestTimeout = settings.TestTimeout;
CurrentSettings.TreatClassAndAssemblyCleanupWarningsAsErrors = settings.TreatClassAndAssemblyCleanupWarningsAsErrors;
CurrentSettings.AssemblyInitializeTimeout = settings.AssemblyInitializeTimeout;
CurrentSettings.AssemblyCleanupTimeout = settings.AssemblyCleanupTimeout;
CurrentSettings.ConsiderEmptyDataSourceAsInconclusive = settings.ConsiderEmptyDataSourceAsInconclusive;
CurrentSettings.ClassInitializeTimeout = settings.ClassInitializeTimeout;
CurrentSettings.ClassCleanupTimeout = settings.ClassCleanupTimeout;
CurrentSettings.TestInitializeTimeout = settings.TestInitializeTimeout;
CurrentSettings.TestCleanupTimeout = settings.TestCleanupTimeout;
CurrentSettings.ConsiderFixturesAsSpecialTests = settings.ConsiderFixturesAsSpecialTests;
CurrentSettings.CooperativeCancellationTimeout = settings.CooperativeCancellationTimeout;
CurrentSettings.TreatDiscoveryWarningsAsErrors = settings.TreatDiscoveryWarningsAsErrors;
}

/// <summary>
Expand Down Expand Up @@ -693,6 +700,21 @@ private static MSTestSettings ToSettings(XmlReader reader, IMessageLogger? logge
break;
}

case "ORDERTESTSBYNAMEINCLASS":
{
string value = reader.ReadInnerXml();
if (bool.TryParse(value, out result))
{
settings.OrderTestsByNameInClass = result;
}
else
{
logger?.SendMessage(TestMessageLevel.Warning, string.Format(CultureInfo.CurrentCulture, Resource.InvalidValue, value, "OrderTestsByNameInClass"));
}

break;
}

default:
{
PlatformServiceProvider.Instance.SettingsProvider.Load(reader.ReadSubtree());
Expand Down

0 comments on commit 4959941

Please sign in to comment.