diff options
author | Keting Yang <ketyang@microsoft.com> | 2020-01-17 20:57:53 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-17 20:57:53 +0300 |
commit | 30e46306561aad819166523a1de8351bac6a5afb (patch) | |
tree | 67f966f8d6607ad423718c98cbce925d77a885f0 /main/src/addins/MonoDevelop.UnitTesting | |
parent | 53a8f09c54d29561bba3c2fd28c5a83ba52b0802 (diff) | |
parent | b0bc034b99e91e8fce95c737f8c00b8002900e34 (diff) |
Merge pull request #9480 from mono/vsts-1042673-NUnit-nesting
[Unit Test] Make the nesting logic for vstest and NUnit(Mono) consistent
Diffstat (limited to 'main/src/addins/MonoDevelop.UnitTesting')
3 files changed, 146 insertions, 4 deletions
diff --git a/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.Tests/MonoDevelop.UnitTesting.Tests.csproj b/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.Tests/MonoDevelop.UnitTesting.Tests.csproj index 98c4976552..9b809f88cc 100644 --- a/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.Tests/MonoDevelop.UnitTesting.Tests.csproj +++ b/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.Tests/MonoDevelop.UnitTesting.Tests.csproj @@ -59,6 +59,11 @@ <Name>MonoDevelop.DotNetCore</Name> <Private>False</Private> </ProjectReference> + <ProjectReference Include="..\..\MonoDevelop.UnitTesting.NUnit\MonoDevelop.UnitTesting.NUnit.csproj"> + <Project>{6224D87E-2AC1-4D9F-91ED-714F797297BF}</Project> + <Name>MonoDevelop.UnitTesting.NUnit</Name> + <Private>False</Private> + </ProjectReference> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> -</Project>
\ No newline at end of file +</Project> diff --git a/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.Tests/MonoDevelop.UnitTesting.Tests/VsTestUnitTestTests.cs b/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.Tests/MonoDevelop.UnitTesting.Tests/VsTestUnitTestTests.cs index df37e68ea1..8263e0d142 100644 --- a/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.Tests/MonoDevelop.UnitTesting.Tests/VsTestUnitTestTests.cs +++ b/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.Tests/MonoDevelop.UnitTesting.Tests/VsTestUnitTestTests.cs @@ -24,8 +24,9 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -using Microsoft.VisualStudio.TestPlatform.ObjectModel;
-using MonoDevelop.UnitTesting.VsTest;
+using Microsoft.VisualStudio.TestPlatform.ObjectModel; +using MonoDevelop.UnitTesting.NUnit; +using MonoDevelop.UnitTesting.VsTest; using NUnit.Framework; using System; using UnitTests; @@ -121,7 +122,141 @@ namespace MonoDevelop.UnitTesting.Tests { FixtureTypeNamespace = fixtureTypeNamespace; FixtureTypeName = fixtureTypeName; + } } } + + [TestFixture] + class NUnitTestUnitTestTests : TestBase + { + + /// <summary> + /// VSTS Bug 1042673: [Bug] Make the nesting for Mono NUnit test consistent with the vstests (mstest, nunit, xunit) + /// </summary> + [Test] + public void TestVSTS1042673 () + { + var case1 = new NUnitTestSuite (null, DirectClassCase ()); + var case2 = new NUnitTestSuite (null, NamespaceWithDot ()); + var case3 = new NUnitTestSuite (null, NestedNamespace ()); + var case4 = new NUnitTestSuite (null, NamespaceNoDot ()); + + Assert.AreEqual(case1.Tests[0].Title, "TestClass"); + Assert.AreEqual(case2.Tests[0].Title, "A.B"); + Assert.AreEqual(case3.Tests[0].Title, "A.B.C"); + Assert.AreEqual(case4.Tests[0].Title, "A"); + + } + + NunitTestInfo DirectClassCase () + { + NunitTestInfo classInfo = new NunitTestInfo { + FixtureTypeName = "TestClass", + FixtureTypeNamespace = "", + Name = "TestClass" + }; + + NunitTestInfo methodInfo = new NunitTestInfo { + FixtureTypeName = "TestClass", + FixtureTypeNamespace = "", + Name = "TestMethod" + }; + classInfo.Tests [0] = methodInfo; + + return classInfo; + } + + NunitTestInfo NamespaceWithDot () + { + NunitTestInfo namespaceInfo = new NunitTestInfo { + FixtureTypeName = "", + FixtureTypeNamespace = "", + Name = "A" + }; + NunitTestInfo namespaceInfo2 = new NunitTestInfo { + FixtureTypeName = "", + FixtureTypeNamespace = "", + Name = "B" + }; + namespaceInfo.Tests [0] = namespaceInfo2; + + NunitTestInfo classInfo = new NunitTestInfo { + FixtureTypeName = "TestClassAB", + FixtureTypeNamespace = "A.B", + Name = "TestClassAB" + }; + namespaceInfo2.Tests [0] = classInfo; + + NunitTestInfo methodInfo = new NunitTestInfo { + FixtureTypeName = "TestClassAB", + FixtureTypeNamespace = "A.B", + Name = "TestMethodAB" + }; + classInfo.Tests [0] = methodInfo; + + return namespaceInfo; + } + + NunitTestInfo NestedNamespace () + { + NunitTestInfo namespaceInfo = new NunitTestInfo { + FixtureTypeName = "", + FixtureTypeNamespace = "", + Name = "A" + }; + NunitTestInfo namespaceInfo2 = new NunitTestInfo { + FixtureTypeName = "", + FixtureTypeNamespace = "", + Name = "B" + }; + namespaceInfo.Tests [0] = namespaceInfo2; + NunitTestInfo namespaceInfo3 = new NunitTestInfo { + FixtureTypeName = "", + FixtureTypeNamespace = "", + Name = "C" + }; + namespaceInfo2.Tests [0] = namespaceInfo3; + + NunitTestInfo classInfo = new NunitTestInfo { + FixtureTypeName = "TestClassABC", + FixtureTypeNamespace = "A.B.C", + Name = "TestClassABC" + }; + namespaceInfo3.Tests [0] = classInfo; + + NunitTestInfo methodInfo = new NunitTestInfo { + FixtureTypeName = "TestClassABC", + FixtureTypeNamespace = "A.B.C", + Name = "TestMethodABC" + }; + classInfo.Tests [0] = methodInfo; + + return namespaceInfo; + } + + NunitTestInfo NamespaceNoDot () + { + NunitTestInfo namespaceInfo = new NunitTestInfo { + FixtureTypeName = "", + FixtureTypeNamespace = "", + Name = "A" + }; + + NunitTestInfo classInfo = new NunitTestInfo { + FixtureTypeName = "TestClassA", + FixtureTypeNamespace = "A", + Name = "TestClassA" + }; + namespaceInfo.Tests [0] = classInfo; + + NunitTestInfo methodInfo = new NunitTestInfo { + FixtureTypeName = "TestClassA", + FixtureTypeNamespace = "A", + Name = "TestMethodA" + }; + classInfo.Tests [0] = methodInfo; + + return namespaceInfo; + } } } diff --git a/main/src/addins/MonoDevelop.UnitTesting/Services/UnitTest.cs b/main/src/addins/MonoDevelop.UnitTesting/Services/UnitTest.cs index 8a7bcce3bc..9dfa120ed4 100644 --- a/main/src/addins/MonoDevelop.UnitTesting/Services/UnitTest.cs +++ b/main/src/addins/MonoDevelop.UnitTesting/Services/UnitTest.cs @@ -43,6 +43,7 @@ namespace MonoDevelop.UnitTesting public abstract class UnitTest: IDisposable { string name; + string title; IResultsStore resultsStore; internal UnitTestResult lastResult; UnitTest parent; @@ -190,7 +191,8 @@ namespace MonoDevelop.UnitTesting } public virtual string Title { - get { return Name; } + get { return title ?? name; } + set { title = value; } } public TestStatus Status { |