Skip to content

Commit

Permalink
Merge pull request #85 from unoplatform/dev/sb/displayname
Browse files Browse the repository at this point in the history
feat: Add support for DisplayName
  • Loading branch information
kazo0 authored Mar 21, 2023
2 parents 6a2c15b + e9a44b5 commit cbf16c3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 18 deletions.
7 changes: 7 additions & 0 deletions src/TestApp/shared/SanityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Uno.UI.RuntimeTests.Engine.Library/UI/TestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ internal record TestCase
{
public object[] Parameters { get; init; } = Array.Empty<object>();

public string? DisplayName { get; init; }

public PointerDeviceType? Pointer { get; init; }

/// <inheritdoc />
Expand Down
42 changes: 25 additions & 17 deletions src/Uno.UI.RuntimeTests.Engine.Library/UI/UnitTestMethodInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Uno.UI.RuntimeTests;

internal record UnitTestMethodInfo
{
private readonly List<object[]> _casesParameters;
private readonly List<ITestDataSource> _casesParameters;
private readonly IList<PointerDeviceType> _injectedPointerTypes;

public UnitTestMethodInfo(object testClassInstance, MethodInfo method)
Expand All @@ -30,18 +30,11 @@ public UnitTestMethodInfo(object testClassInstance, MethodInfo method)
.SingleOrDefault()
?.ExceptionType;

_casesParameters = method
.GetCustomAttributes<DataRowAttribute>()
.Select(d => d.Data)
_casesParameters = method
.GetCustomAttributes()
.Where(x => x is ITestDataSource)
.Cast<ITestDataSource>()
.ToList();
if (method.GetCustomAttribute<DynamicDataAttribute>() is {} dynamicData)
{
_casesParameters.AddRange(dynamicData.GetData(method));
}
if (_casesParameters is { Count: 0 })
{
_casesParameters.Add(Array.Empty<object>());
}

_injectedPointerTypes = method
.GetCustomAttributes<InjectedPointerAttribute>()
Expand Down Expand Up @@ -83,17 +76,32 @@ public bool IsIgnored(out string ignoreMessage)

public IEnumerable<TestCase> GetCases()
{
var cases = _casesParameters.Select(parameters => new TestCase { Parameters = parameters });
List<TestCase> cases = Enumerable.Empty<TestCase>().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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit cbf16c3

Please sign in to comment.