diff options
author | Keting Yang <> | 2020-01-08 23:23:26 +0300 |
---|---|---|
committer | monojenkins <jo.shields+jenkins@xamarin.com> | 2020-01-09 13:21:46 +0300 |
commit | cc9a934fc0e5a6aab0429f3d68bcf25243c242a3 (patch) | |
tree | ec340e5d21f2ce92d429b44e775d476cc747d38d /main/src/addins/MonoDevelop.UnitTesting.NUnit | |
parent | 3e85d3e095948544f8b6e8da0c2932ff00c6749b (diff) |
Fix the nesting logic for NUnit Test:
[1] Allow setting the title of a unit test
[2] Handle the nesting logic while building the tests (get rid of the use of CanMergeWithParent, which is only used in TestNodeBuilder)
Diffstat (limited to 'main/src/addins/MonoDevelop.UnitTesting.NUnit')
2 files changed, 59 insertions, 43 deletions
diff --git a/main/src/addins/MonoDevelop.UnitTesting.NUnit/MonoDevelop.UnitTesting.NUnit/NUnitAssemblyTestSuite.cs b/main/src/addins/MonoDevelop.UnitTesting.NUnit/MonoDevelop.UnitTesting.NUnit/NUnitAssemblyTestSuite.cs index a1aed30e25..4a9e1556a5 100644 --- a/main/src/addins/MonoDevelop.UnitTesting.NUnit/MonoDevelop.UnitTesting.NUnit/NUnitAssemblyTestSuite.cs +++ b/main/src/addins/MonoDevelop.UnitTesting.NUnit/MonoDevelop.UnitTesting.NUnit/NUnitAssemblyTestSuite.cs @@ -273,23 +273,34 @@ namespace MonoDevelop.UnitTesting.NUnit var newTest = new NUnitTestSuite (this, test); newTest.FixtureTypeName = test.FixtureTypeName; newTest.FixtureTypeNamespace = test.FixtureTypeNamespace; - Tests.Add (newTest); - var queue = new Queue<NUnitTestSuite> (); - queue.Enqueue (newTest); - - var forceLoad = newTest.Tests; - while (queue.Count != 0) { - NUnitTestSuite unhandledList = queue.Dequeue (); - foreach (NUnitTestSuite unhandledTest in unhandledList.UnhandledTests) { - Tests.Add (unhandledTest); + bool isNameSpace = false; + if (test.Tests != null) { + foreach (NunitTestInfo child in test.Tests) { + if (child.Tests != null) { + isNameSpace = true; + } } - foreach (UnitTest unhandledTest in unhandledList.Tests) { - if (unhandledTest is NUnitTestSuite) { - queue.Enqueue ((NUnitTestSuite)unhandledTest); + } + + bool hasClassAsChild = false; + if (test.Tests != null) { + foreach (NunitTestInfo child in test.Tests) { + if (child.Tests != null && child.Tests[0].Tests == null) { + hasClassAsChild = true; } } } + + if (!isNameSpace || hasClassAsChild) { + Tests.Add (newTest); + } + + var forceLoad = newTest.Tests; + foreach (NUnitTestSuite child in newTest.ChildNamespaces) { + child.Title = newTest.Title + "." + child.Title; + Tests.Add (child); + } } oldList = new UnitTest [Tests.Count]; Tests.CopyTo (oldList, 0); diff --git a/main/src/addins/MonoDevelop.UnitTesting.NUnit/MonoDevelop.UnitTesting.NUnit/NUnitTestSuite.cs b/main/src/addins/MonoDevelop.UnitTesting.NUnit/MonoDevelop.UnitTesting.NUnit/NUnitTestSuite.cs index c6eaa10bf3..883b7bc3f7 100644 --- a/main/src/addins/MonoDevelop.UnitTesting.NUnit/MonoDevelop.UnitTesting.NUnit/NUnitTestSuite.cs +++ b/main/src/addins/MonoDevelop.UnitTesting.NUnit/MonoDevelop.UnitTesting.NUnit/NUnitTestSuite.cs @@ -37,7 +37,7 @@ namespace MonoDevelop.UnitTesting.NUnit NUnitAssemblyTestSuite rootSuite; string fullName; - UnitTestCollection unhandledTests; + UnitTestCollection childNamespaces; public NUnitTestSuite (NUnitAssemblyTestSuite rootSuite, NunitTestInfo tinfo): base (tinfo.Name) { @@ -45,33 +45,25 @@ namespace MonoDevelop.UnitTesting.NUnit this.testInfo = tinfo; this.rootSuite = rootSuite; this.TestSourceCodeDocumentId = this.TestId = tinfo.TestId; - this.canMergeWithParent = !string.IsNullOrEmpty (tinfo.PathName) && - string.IsNullOrEmpty (tinfo.FixtureTypeName) && - string.IsNullOrEmpty (tinfo.FixtureTypeNamespace); - this.unhandledTests = new UnitTestCollection (); + this.childNamespaces = new UnitTestCollection (); } - bool canMergeWithParent; - public override bool CanMergeWithParent { - get { - return canMergeWithParent; - } - } - public override bool HasTests { get { return true; } } - public UnitTestCollection UnhandledTests { + public UnitTestCollection ChildNamespaces { get { - return unhandledTests; + return childNamespaces; } } public string ClassName { - get { return fullName; } + get { + return fullName; + } } protected override UnitTestResult OnRun (TestContext testContext) @@ -91,29 +83,42 @@ namespace MonoDevelop.UnitTesting.NUnit return; foreach (NunitTestInfo test in testInfo.Tests) { - UnitTest newTest; if (test.Tests != null) { - newTest = new NUnitTestSuite (rootSuite, test); - } else { - newTest = new NUnitTestCase (rootSuite, test, ClassName); - } - newTest.FixtureTypeName = test.FixtureTypeName; - newTest.FixtureTypeNamespace = test.FixtureTypeNamespace; + var newTest = new NUnitTestSuite (rootSuite, test); + newTest.FixtureTypeName = test.FixtureTypeName; + newTest.FixtureTypeNamespace = test.FixtureTypeNamespace; - bool isNameSpace = false; - if (test.Tests != null) { - foreach (NunitTestInfo info in test.Tests) { - if (info.Tests != null) { + bool isNameSpace = false; + foreach (NunitTestInfo child in test.Tests) { + if (child.Tests != null) { isNameSpace = true; } } - } - if (isNameSpace) { - var newNamespaceTestSuite = (NUnitTestSuite)newTest; - newNamespaceTestSuite.testInfo.Name = newNamespaceTestSuite.testInfo.TestId; - unhandledTests.Add (newNamespaceTestSuite); + bool hasClassAsChild = false; + foreach (NunitTestInfo child in test.Tests) { + if (child.Tests != null && child.Tests [0].Tests == null) { + hasClassAsChild = true; + } + } + + if (isNameSpace) { + var forceLoad = newTest.Tests; + foreach (var child in newTest.ChildNamespaces) { + //Console.WriteLine (newTest.Title + " " + child.Title); + child.Title = newTest.Title + "." + child.Title; + childNamespaces.Add (child); + } + if (hasClassAsChild) { + childNamespaces.Add (newTest); + } + } else { + Tests.Add (newTest); + } } else { + var newTest = new NUnitTestCase (rootSuite, test, ClassName); + newTest.FixtureTypeName = test.FixtureTypeName; + newTest.FixtureTypeNamespace = test.FixtureTypeNamespace; Tests.Add (newTest); } } |