Skip to content

Commit

Permalink
Fix for #20 TestCaseSource tests are failing in editor
Browse files Browse the repository at this point in the history
  • Loading branch information
eliatlas committed Sep 24, 2021
1 parent 51b0745 commit 03f7a05
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,17 @@ List<object[]> GetTestData(MethodInfo methodInfo)
var enumerator = GetTestCaseSource(methodInfo, item.SourceType, item.SourceName, item.MethodParams);
foreach (var item2 in enumerator)
{
var item3 = item2 as TestCaseData;
if (item3 != null)
{
testCases.Add(item3.Arguments);
}
if (item2 is TestCaseData item3)
{
testCases.Add(item3.Arguments);
}
else
{
if (item2 is IEnumerable item4)
{
testCases.Add(item4.Cast<object>().ToArray());
}
}
}
}

Expand Down
25 changes: 13 additions & 12 deletions RuntimeUnitTestToolkit/Assets/Scripts/Tests/SampleGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,30 +201,31 @@ public IEnumerator UnityTearDown()

public class TestCaseSourceGroup
{
private static readonly TestCaseData[] DivideCases =
private static readonly object[] ObjectTestCases =
{
new TestCaseData(12, 3, 4),
new TestCaseData(12, 2, 6),
new TestCaseData(12, 4, 3)
new object[] { 12, 3, 4 },
new object[] { 12, 2, 6 },
new object[] { 12, 4, 3 }
};


[Test, TestCaseSource(nameof(GetTestCases))]
[Test, TestCaseSource(nameof(ObjectTestCases))]
public void DivideTest(int n, int d, int q)
{
Assert.AreEqual(q, n / d);
}

[UnityTest, TestCaseSource(nameof(GetTestCases))]
private static readonly TestCaseData[] TestCaseDataCases =
{
new TestCaseData(12, 3, 4).Returns(null),
new TestCaseData(12, 2, 6).Returns(null),
new TestCaseData(12, 4, 3).Returns(null)
};

[UnityTest, TestCaseSource(nameof(TestCaseDataCases))]
public IEnumerator DivideUnityTest(int n, int d, int q)
{
Assert.AreEqual(q, n / d);
yield return null;
}

private static IEnumerable<TestCaseData> GetTestCases()
{
return DivideCases.Select((t, i) => t.SetName($"{i}").Returns(null));
}
}
}

0 comments on commit 03f7a05

Please sign in to comment.