From 03f7a05c408a3cf8b4d230c9df15914e34fce891 Mon Sep 17 00:00:00 2001 From: Eli Atlas Date: Fri, 24 Sep 2021 15:04:47 +0300 Subject: [PATCH] Fix for #20 TestCaseSource tests are failing in editor --- .../RuntimeUnitTestToolkit/UnitTestData.cs | 16 ++++++++---- .../Assets/Scripts/Tests/SampleGroup.cs | 25 ++++++++++--------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/RuntimeUnitTestToolkit/Assets/RuntimeUnitTestToolkit/UnitTestData.cs b/RuntimeUnitTestToolkit/Assets/RuntimeUnitTestToolkit/UnitTestData.cs index 47b658b..b4bbce3 100644 --- a/RuntimeUnitTestToolkit/Assets/RuntimeUnitTestToolkit/UnitTestData.cs +++ b/RuntimeUnitTestToolkit/Assets/RuntimeUnitTestToolkit/UnitTestData.cs @@ -322,11 +322,17 @@ List 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().ToArray()); + } + } } } diff --git a/RuntimeUnitTestToolkit/Assets/Scripts/Tests/SampleGroup.cs b/RuntimeUnitTestToolkit/Assets/Scripts/Tests/SampleGroup.cs index aa9fdea..be7b073 100644 --- a/RuntimeUnitTestToolkit/Assets/Scripts/Tests/SampleGroup.cs +++ b/RuntimeUnitTestToolkit/Assets/Scripts/Tests/SampleGroup.cs @@ -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 GetTestCases() - { - return DivideCases.Select((t, i) => t.SetName($"{i}").Returns(null)); - } } } \ No newline at end of file