diff --git a/src/TestApp/shared/SanityTests.cs b/src/TestApp/shared/SanityTests.cs index 6269b4e..c2b0039 100644 --- a/src/TestApp/shared/SanityTests.cs +++ b/src/TestApp/shared/SanityTests.cs @@ -39,6 +39,13 @@ public async Task When_Test_ContentHelper() await UnitTestsUIContentHelper.WaitForLoaded(SUT); } + [TestMethod] + [DataRow("hello", DisplayName = "hello test")] + [DataRow("goodbye", DisplayName = "goodbye test")] + public void Is_Sane_With_Cases(string text) + { + } + #if DEBUG [TestMethod] public async Task No_Longer_Sane() // expected to fail diff --git a/src/Uno.UI.RuntimeTests.Engine.Library/UI/TestCase.cs b/src/Uno.UI.RuntimeTests.Engine.Library/UI/TestCase.cs index c341b90..9bbec27 100644 --- a/src/Uno.UI.RuntimeTests.Engine.Library/UI/TestCase.cs +++ b/src/Uno.UI.RuntimeTests.Engine.Library/UI/TestCase.cs @@ -12,6 +12,8 @@ internal record TestCase { public object[] Parameters { get; init; } = Array.Empty(); + public string? DisplayName { get; init; } + public PointerDeviceType? Pointer { get; init; } /// diff --git a/src/Uno.UI.RuntimeTests.Engine.Library/UI/UnitTestMethodInfo.cs b/src/Uno.UI.RuntimeTests.Engine.Library/UI/UnitTestMethodInfo.cs index bc5081a..1207771 100644 --- a/src/Uno.UI.RuntimeTests.Engine.Library/UI/UnitTestMethodInfo.cs +++ b/src/Uno.UI.RuntimeTests.Engine.Library/UI/UnitTestMethodInfo.cs @@ -13,7 +13,7 @@ namespace Uno.UI.RuntimeTests; internal record UnitTestMethodInfo { - private readonly List _casesParameters; + private readonly List _casesParameters; private readonly IList _injectedPointerTypes; public UnitTestMethodInfo(object testClassInstance, MethodInfo method) @@ -30,18 +30,11 @@ public UnitTestMethodInfo(object testClassInstance, MethodInfo method) .SingleOrDefault() ?.ExceptionType; - _casesParameters = method - .GetCustomAttributes() - .Select(d => d.Data) + _casesParameters = method + .GetCustomAttributes() + .Where(x => x is ITestDataSource) + .Cast() .ToList(); - if (method.GetCustomAttribute() is {} dynamicData) - { - _casesParameters.AddRange(dynamicData.GetData(method)); - } - if (_casesParameters is { Count: 0 }) - { - _casesParameters.Add(Array.Empty()); - } _injectedPointerTypes = method .GetCustomAttributes() @@ -83,17 +76,32 @@ public bool IsIgnored(out string ignoreMessage) public IEnumerable GetCases() { - var cases = _casesParameters.Select(parameters => new TestCase { Parameters = parameters }); + List cases = Enumerable.Empty().ToList(); + + if (_casesParameters is { Count: 0 }) + { + cases.Add(new TestCase()); + } + + foreach (var testCaseSource in _casesParameters) + { + foreach (var caseData in testCaseSource.GetData(Method)) + { + var data = testCaseSource.GetData(Method) + .SelectMany(x => x) + .ToArray(); + + cases.Add(new TestCase { Parameters = data, DisplayName = testCaseSource.GetDisplayName(Method, data) }); + } + } if (_injectedPointerTypes.Any()) { - var currentCases = cases.ToList(); - cases = _injectedPointerTypes.SelectMany(pointer => currentCases.Select(testCase => testCase with { Pointer = pointer })); + var currentCases = cases; + cases = _injectedPointerTypes.SelectMany(pointer => currentCases.Select(testCase => testCase with { Pointer = pointer })).ToList(); } return cases; } } - - #endif \ No newline at end of file diff --git a/src/Uno.UI.RuntimeTests.Engine.Library/UI/UnitTestsControl.cs b/src/Uno.UI.RuntimeTests.Engine.Library/UI/UnitTestsControl.cs index 77a966f..4a8c27b 100644 --- a/src/Uno.UI.RuntimeTests.Engine.Library/UI/UnitTestsControl.cs +++ b/src/Uno.UI.RuntimeTests.Engine.Library/UI/UnitTestsControl.cs @@ -750,7 +750,7 @@ private async Task ExecuteTestsForInstance( async Task InvokeTestMethod(TestCase testCase) { - var fullTestName = testName + testCase.ToString(); + var fullTestName = string.IsNullOrWhiteSpace(testCase.DisplayName) ? testName + testCase.ToString() : testCase.DisplayName!; if (_currentRun is null) {