From 255a16bb3dd36e1206273feb9aa7ca35c790f1b0 Mon Sep 17 00:00:00 2001 From: Jayarani Garg Date: Wed, 31 Aug 2016 15:15:00 +0530 Subject: [PATCH 1/7] Bug Fix #258333 with UT --- .../Execution/TestExecutionManager.cs | 5 ++++- .../Execution/TestExecutionManagerTests.cs | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Adapter/MSTestAdapter/Execution/TestExecutionManager.cs b/src/Adapter/MSTestAdapter/Execution/TestExecutionManager.cs index ce183cdb87..939ef232f2 100644 --- a/src/Adapter/MSTestAdapter/Execution/TestExecutionManager.cs +++ b/src/Adapter/MSTestAdapter/Execution/TestExecutionManager.cs @@ -104,6 +104,9 @@ public void RunTests(IEnumerable sources, IRunContext runContext, IFrame // discover the tests (new UnitTestDiscoverer()).DiscoverTestsInSource(source, logger, discoverySink, runContext?.RunSettings); tests.AddRange(discoverySink.Tests); + + //Clear discoverSinksTests so that it just stores test for one source at one point of time + discoverySink.Tests.Clear(); } bool isDeploymentDone = PlatformServiceProvider.Instance.TestDeployment.Deploy(tests, runContext, frameworkHandle); @@ -123,7 +126,7 @@ public void RunTests(IEnumerable sources, IRunContext runContext, IFrame /// /// Execute the parameter tests /// - private void ExecuteTests(IEnumerable tests, IRunContext runContext, IFrameworkHandle frameworkHandle, bool isDeploymentDone) + internal virtual void ExecuteTests(IEnumerable tests, IRunContext runContext, IFrameworkHandle frameworkHandle, bool isDeploymentDone) { var testsBySource = (from test in tests group test by test.Source into testGroup diff --git a/test/UnitTests/MSTestAdapter.Tests/Execution/TestExecutionManagerTests.cs b/test/UnitTests/MSTestAdapter.Tests/Execution/TestExecutionManagerTests.cs index 8c8ba87964..79b0b3e2b0 100644 --- a/test/UnitTests/MSTestAdapter.Tests/Execution/TestExecutionManagerTests.cs +++ b/test/UnitTests/MSTestAdapter.Tests/Execution/TestExecutionManagerTests.cs @@ -352,6 +352,14 @@ public void RunTestsForSourceShouldPassInDeploymentInformationAsPropertiesToTheT Assert.IsNotNull(DummyTestClass.TestContextProperties); } + [TestMethodV1] + public void RunTestsForMultipleSourcesShouldRunEachTestJustOnce() + { + var sources = new List { Assembly.GetExecutingAssembly().Location, Assembly.GetExecutingAssembly().Location }; + TestableTestExecutionManager testableTestExecutionmanager = new TestableTestExecutionManager(); + testableTestExecutionmanager.RunTests(sources, this.runContext, this.frameworkHandle, this.cancellationToken); + } + #endregion #region private methods @@ -567,6 +575,14 @@ public bool MatchTestCase(TestCase testCase, Func propertyValueP } } + internal class TestableTestExecutionManager : TestExecutionManager + { + internal override void ExecuteTests(IEnumerable tests, IRunContext runContext, + IFrameworkHandle frameworkHandle, bool isDeploymentDone) + { + Assert.AreEqual(tests.Count(), 2); + } + } #endregion } } From 86f8d1315ba924f9a684d8d01ea88c550b9f44c4 Mon Sep 17 00:00:00 2001 From: Jayarani Garg Date: Wed, 31 Aug 2016 16:13:36 +0530 Subject: [PATCH 2/7] Correcting UT --- .../Execution/TestExecutionManager.cs | 7 ++++++- src/Adapter/MSTestAdapter/MSTestDiscoverer.cs | 2 +- .../Discovery/UnitTestDiscovererTests.cs | 14 ++++++++++++++ .../Execution/TestExecutionManagerTests.cs | 9 ++++++++- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/Adapter/MSTestAdapter/Execution/TestExecutionManager.cs b/src/Adapter/MSTestAdapter/Execution/TestExecutionManager.cs index 939ef232f2..cf55868270 100644 --- a/src/Adapter/MSTestAdapter/Execution/TestExecutionManager.cs +++ b/src/Adapter/MSTestAdapter/Execution/TestExecutionManager.cs @@ -102,7 +102,7 @@ public void RunTests(IEnumerable sources, IRunContext runContext, IFrame var logger = (IMessageLogger)frameworkHandle; // discover the tests - (new UnitTestDiscoverer()).DiscoverTestsInSource(source, logger, discoverySink, runContext?.RunSettings); + this.GetUnitTestDiscoverer().DiscoverTestsInSource(source, logger, discoverySink, runContext?.RunSettings); tests.AddRange(discoverySink.Tests); //Clear discoverSinksTests so that it just stores test for one source at one point of time @@ -280,6 +280,11 @@ private void ExecuteTestsWithTestRunner( this.LogWarnings(testExecutionRecorder, warnings); } + internal virtual UnitTestDiscoverer GetUnitTestDiscoverer() + { + return new UnitTestDiscoverer(); + } + private void CacheSessionParameters(IRunContext runContext, ITestExecutionRecorder testExecutionRecorder) { if (!string.IsNullOrEmpty(runContext?.RunSettings?.SettingsXml)) diff --git a/src/Adapter/MSTestAdapter/MSTestDiscoverer.cs b/src/Adapter/MSTestAdapter/MSTestDiscoverer.cs index d0f6dcd250..8f4ec645f2 100644 --- a/src/Adapter/MSTestAdapter/MSTestDiscoverer.cs +++ b/src/Adapter/MSTestAdapter/MSTestDiscoverer.cs @@ -117,7 +117,7 @@ internal void DiscoverTests( /// The logger. /// The discovery Sink. /// The run settings. - internal void DiscoverTestsInSource( + internal virtual void DiscoverTestsInSource( string source, IMessageLogger logger, ITestCaseDiscoverySink discoverySink, diff --git a/test/UnitTests/MSTestAdapter.Tests/Discovery/UnitTestDiscovererTests.cs b/test/UnitTests/MSTestAdapter.Tests/Discovery/UnitTestDiscovererTests.cs index f269ab4933..7e8e758b42 100644 --- a/test/UnitTests/MSTestAdapter.Tests/Discovery/UnitTestDiscovererTests.cs +++ b/test/UnitTests/MSTestAdapter.Tests/Discovery/UnitTestDiscovererTests.cs @@ -261,4 +261,18 @@ public DummyNavigationData(string fileName, int minLineNumber, int maxLineNumber public int MaxLineNumber { get; set; } } + + internal class TestableUnitTestDiscoverer : UnitTestDiscoverer + { + internal override void DiscoverTestsInSource(string source, + IMessageLogger logger, + ITestCaseDiscoverySink discoverySink, + IRunSettings runSettings) + { + var testCase1 = new TestCase("A", new System.Uri("executor://testExecutor"), source); + var testCase2 = new TestCase("B", new System.Uri("executor://testExecutor"), source); + discoverySink.SendTestCase(testCase1); + discoverySink.SendTestCase(testCase2); + } + } } \ No newline at end of file diff --git a/test/UnitTests/MSTestAdapter.Tests/Execution/TestExecutionManagerTests.cs b/test/UnitTests/MSTestAdapter.Tests/Execution/TestExecutionManagerTests.cs index 79b0b3e2b0..11c6294486 100644 --- a/test/UnitTests/MSTestAdapter.Tests/Execution/TestExecutionManagerTests.cs +++ b/test/UnitTests/MSTestAdapter.Tests/Execution/TestExecutionManagerTests.cs @@ -23,6 +23,7 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution; using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Discovery; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.TestableImplementations; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; @@ -580,7 +581,13 @@ internal class TestableTestExecutionManager : TestExecutionManager internal override void ExecuteTests(IEnumerable tests, IRunContext runContext, IFrameworkHandle frameworkHandle, bool isDeploymentDone) { - Assert.AreEqual(tests.Count(), 2); + //There are two sources and each source has 2 tests + Assert.AreEqual(tests.Count(), 4); + } + + internal override UnitTestDiscoverer GetUnitTestDiscoverer() + { + return new TestableUnitTestDiscoverer(); } } #endregion From 6ce370bede071a517c17385c0aa1ea0302addb7c Mon Sep 17 00:00:00 2001 From: Jayarani Garg Date: Wed, 31 Aug 2016 18:30:46 +0530 Subject: [PATCH 3/7] Editing UT --- .../Execution/TestExecutionManagerTests.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/test/UnitTests/MSTestAdapter.Tests/Execution/TestExecutionManagerTests.cs b/test/UnitTests/MSTestAdapter.Tests/Execution/TestExecutionManagerTests.cs index 11c6294486..9c25793a7a 100644 --- a/test/UnitTests/MSTestAdapter.Tests/Execution/TestExecutionManagerTests.cs +++ b/test/UnitTests/MSTestAdapter.Tests/Execution/TestExecutionManagerTests.cs @@ -356,9 +356,17 @@ public void RunTestsForSourceShouldPassInDeploymentInformationAsPropertiesToTheT [TestMethodV1] public void RunTestsForMultipleSourcesShouldRunEachTestJustOnce() { + int testsCount = 0; var sources = new List { Assembly.GetExecutingAssembly().Location, Assembly.GetExecutingAssembly().Location }; TestableTestExecutionManager testableTestExecutionmanager = new TestableTestExecutionManager(); + + testableTestExecutionmanager.ExecuteTestsWrapper = (tests, runContext, frameworkHandle, isDeploymentDone) => + { + testsCount += tests.Count(); + }; + testableTestExecutionmanager.RunTests(sources, this.runContext, this.frameworkHandle, this.cancellationToken); + Assert.AreEqual(testsCount, 4); } #endregion @@ -581,14 +589,18 @@ internal class TestableTestExecutionManager : TestExecutionManager internal override void ExecuteTests(IEnumerable tests, IRunContext runContext, IFrameworkHandle frameworkHandle, bool isDeploymentDone) { - //There are two sources and each source has 2 tests - Assert.AreEqual(tests.Count(), 4); + if (this.ExecuteTestsWrapper != null) + { + this.ExecuteTestsWrapper.Invoke(tests, runContext, frameworkHandle, isDeploymentDone); + } } internal override UnitTestDiscoverer GetUnitTestDiscoverer() { return new TestableUnitTestDiscoverer(); } + + internal Action, IRunContext, IFrameworkHandle, bool> ExecuteTestsWrapper; } #endregion } From 9cd135fa3e8e895559915546183438e21a9da705 Mon Sep 17 00:00:00 2001 From: Jayarani Garg Date: Fri, 2 Sep 2016 17:21:29 +0530 Subject: [PATCH 4/7] Bug Fix #233637 with UT --- .../Services/DesktopTestDataSource.cs | 2 + .../Execution/TestExecutionManager.cs | 9 +++- .../Execution/TestMethodRunner.cs | 1 + .../ObjectModel/UnitTestResult.cs | 13 +++++- .../MSTestAdapter/Resource.Designer.cs | 9 ++++ src/Adapter/MSTestAdapter/Resource.resx | 3 ++ src/TestFramework/vnext/VSTestAttributes.cs | 15 +++++++ .../Services/DesktopTestDataSourceTests.cs | 45 ++++++++++++++++++- .../Execution/TestExecutionManagerTests.cs | 15 ++++++- .../Execution/TestMethodRunnerTests.cs | 4 +- 10 files changed, 110 insertions(+), 6 deletions(-) diff --git a/src/Adapter/MSTestAdapter.PlatformServices.Desktop/Services/DesktopTestDataSource.cs b/src/Adapter/MSTestAdapter.PlatformServices.Desktop/Services/DesktopTestDataSource.cs index 4cb146c11b..010c6b166a 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices.Desktop/Services/DesktopTestDataSource.cs +++ b/src/Adapter/MSTestAdapter.PlatformServices.Desktop/Services/DesktopTestDataSource.cs @@ -113,6 +113,8 @@ public UTF.TestResult[] RunDataDrivenTest(UTF.TestContext testContext, UTF.ITest } + currentResult[0].DatarowIndex = rowIndex; + watch.Stop(); currentResult[0].Duration = watch.Elapsed; diff --git a/src/Adapter/MSTestAdapter/Execution/TestExecutionManager.cs b/src/Adapter/MSTestAdapter/Execution/TestExecutionManager.cs index cf55868270..ee005fdd65 100644 --- a/src/Adapter/MSTestAdapter/Execution/TestExecutionManager.cs +++ b/src/Adapter/MSTestAdapter/Execution/TestExecutionManager.cs @@ -5,6 +5,7 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution using System; using System.Collections.Generic; using System.Diagnostics; + using System.Globalization; using System.IO; using System.Linq; @@ -41,6 +42,7 @@ public TestExecutionManager() { this.TestMethodFilter = new TestMethodFilter(); this.sessionParameters = new Dictionary(); + this.adapterSettings = new MSTestSettings(); } /// @@ -326,7 +328,7 @@ private void LogWarnings(ITestExecutionRecorder testExecutionRecorder, IEnumerab } } - private void SendTestResults(TestCase test, UnitTestResult[] unitTestResults, DateTimeOffset startTime, DateTimeOffset endTime, ITestExecutionRecorder testExecutionRecorder) + internal void SendTestResults(TestCase test, UnitTestResult[] unitTestResults, DateTimeOffset startTime, DateTimeOffset endTime, ITestExecutionRecorder testExecutionRecorder) { if (!(unitTestResults?.Length > 0)) { @@ -342,6 +344,11 @@ private void SendTestResults(TestCase test, UnitTestResult[] unitTestResults, Da } var testResult = unitTestResult.ToTestResult(test, startTime, endTime, adapterSettings.MapInconclusiveToFailed); + + if (unitTestResult.DatarowIndex >= 0) + { + testResult.DisplayName = string.Format(CultureInfo.CurrentCulture, Resource.DataDrivenResultDisplayName, test.DisplayName, unitTestResult.DatarowIndex); + } testExecutionRecorder.RecordEnd(test, testResult.Outcome); if (testResult.Outcome == TestOutcome.Failed) diff --git a/src/Adapter/MSTestAdapter/Execution/TestMethodRunner.cs b/src/Adapter/MSTestAdapter/Execution/TestMethodRunner.cs index d2524f4732..5610515aed 100644 --- a/src/Adapter/MSTestAdapter/Execution/TestMethodRunner.cs +++ b/src/Adapter/MSTestAdapter/Execution/TestMethodRunner.cs @@ -275,6 +275,7 @@ internal UnitTestResult[] ConvertTestResultToUnitTestResult(UTF.TestResult[] res unitTestResult.DebugTrace = results[i].DebugTrace; unitTestResult.Duration = results[i].Duration; unitTestResult.DisplayName = results[i].DisplayName; + unitTestResult.DatarowIndex = results[i].DatarowIndex; unitTestResult.ResultFiles = testContext.GetResultFiles(); unitTestResults[i] = unitTestResult; } diff --git a/src/Adapter/MSTestAdapter/ObjectModel/UnitTestResult.cs b/src/Adapter/MSTestAdapter/ObjectModel/UnitTestResult.cs index ee5211a261..2e5ee73b10 100644 --- a/src/Adapter/MSTestAdapter/ObjectModel/UnitTestResult.cs +++ b/src/Adapter/MSTestAdapter/ObjectModel/UnitTestResult.cs @@ -27,6 +27,7 @@ public class UnitTestResult /// internal UnitTestResult() { + DatarowIndex = -1; } /// @@ -37,6 +38,7 @@ internal UnitTestResult(TestFailedException testFailedException) { this.Outcome = testFailedException.Outcome; this.ErrorMessage = testFailedException.Message; + DatarowIndex = -1; if (testFailedException.StackTraceInformation != null) { @@ -56,6 +58,7 @@ internal UnitTestResult(UnitTestOutcome outcome, string errorMessage) { this.Outcome = outcome; this.ErrorMessage = errorMessage; + DatarowIndex = -1; } /// @@ -113,6 +116,12 @@ internal UnitTestResult(UnitTestOutcome outcome, string errorMessage) /// public int ErrorColumnNumber { get; private set; } + /// + /// Data row index in data source. Set only for results of individual + /// run of data row of a data driven test. + /// + public int DatarowIndex { get; internal set; } + /// /// Gets the result files attached by the test. /// @@ -137,8 +146,8 @@ internal TestResult ToTestResult(TestCase testCase, DateTimeOffset startTime, Da ErrorStackTrace = this.ErrorStackTrace, Outcome = UnitTestOutcomeHelper.ToTestOutcome(this.Outcome, mapInconclusiveToFailed), StartTime = startTime, - EndTime = endTime - }; + EndTime = endTime + }; if (!string.IsNullOrEmpty(this.StandardOut)) { diff --git a/src/Adapter/MSTestAdapter/Resource.Designer.cs b/src/Adapter/MSTestAdapter/Resource.Designer.cs index 6b472a21fb..7e8816f92a 100644 --- a/src/Adapter/MSTestAdapter/Resource.Designer.cs +++ b/src/Adapter/MSTestAdapter/Resource.Designer.cs @@ -106,6 +106,15 @@ internal static string CouldNotInspectTypeDuringDiscovery1 { } } + /// + /// Looks up a localized string similar to {0} (Data Row {1}). + /// + internal static string DataDrivenResultDisplayName { + get { + return ResourceManager.GetString("DataDrivenResultDisplayName", resourceCulture); + } + } + /// /// Looks up a localized string similar to Debug Trace:. /// diff --git a/src/Adapter/MSTestAdapter/Resource.resx b/src/Adapter/MSTestAdapter/Resource.resx index 441e9f6139..ba333f6573 100644 --- a/src/Adapter/MSTestAdapter/Resource.resx +++ b/src/Adapter/MSTestAdapter/Resource.resx @@ -274,4 +274,7 @@ Invalid settings '{0}'. Unexpected XmlElement: '{1}'. + + {0} (Data Row {1}) + \ No newline at end of file diff --git a/src/TestFramework/vnext/VSTestAttributes.cs b/src/TestFramework/vnext/VSTestAttributes.cs index 283cdcb380..06e3c6a2f9 100644 --- a/src/TestFramework/vnext/VSTestAttributes.cs +++ b/src/TestFramework/vnext/VSTestAttributes.cs @@ -313,6 +313,15 @@ public TimeoutAttribute(TestTimeout timeout) /// public class TestResult { + + /// + /// Initializes a new instance of the class. + /// + public TestResult() + { + DatarowIndex = -1; + } + /// /// Gets or sets the display name of the result. Useful when returning multiple results. /// If null then Method name is used as DisplayName. @@ -349,6 +358,12 @@ public class TestResult /// public TimeSpan Duration { get; set; } + /// + /// Data row index in data source. Set only for results of individual + /// run of data row of a data driven test. + /// + public int DatarowIndex { get; set; } + /// /// Gets or sets the return value of the test method. (Currently null always). /// diff --git a/test/UnitTests/MSTestAdapter.PlatformServices.Desktop.Tests/Services/DesktopTestDataSourceTests.cs b/test/UnitTests/MSTestAdapter.PlatformServices.Desktop.Tests/Services/DesktopTestDataSourceTests.cs index ebb617fc60..a726d2468f 100644 --- a/test/UnitTests/MSTestAdapter.PlatformServices.Desktop.Tests/Services/DesktopTestDataSourceTests.cs +++ b/test/UnitTests/MSTestAdapter.PlatformServices.Desktop.Tests/Services/DesktopTestDataSourceTests.cs @@ -151,8 +151,51 @@ public void RunDataDrivenTestsGivesTestResultAsFailedWhenTestMethodFails() Assert.AreEqual(result[0].Outcome, TestFrameworkV2.UnitTestOutcome.Failed); } + [TestMethod] + public void RunDataDrivenTestsShouldSetDataRowIndex() + { + this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new System.IO.StringWriter(), this.properties); + + TestFrameworkV2.DataSourceAttribute dataSourceAttribute = new TestFrameworkV2.DataSourceAttribute( + "Microsoft.VisualStudio.TestTools.DataSource.XML", "DataTestSourceFile.xml", "settings", TestFrameworkV2.DataAccessMethod.Sequential); + + this.mockTestMethodInfo.Setup(ds => ds.GetAttributes(false)) + .Returns(new TestFrameworkV2.DataSourceAttribute[] { dataSourceAttribute }); + + TestFrameworkV2.TestResult testResult = new TestFrameworkV2.TestResult(); + DummyTestClass testClassInstance = new DummyTestClass(); + var methodInfo = typeof(DummyTestClass).GetMethod("PassingTest"); + + this.mockTestMethodInfo.Setup(ds => ds.Invoke(null)). + Callback(() => + { + try + { + testClassInstance.TestContext = this.testContextImplementation; + + var task = methodInfo.Invoke(testClassInstance, null) as Task; + task?.GetAwaiter().GetResult(); + + testResult.Outcome = TestFrameworkV2.UnitTestOutcome.Passed; + } + catch (Exception ex) + { + testResult.Outcome = TestFrameworkV2.UnitTestOutcome.Failed; + testResult.TestFailureException = ex; + } + } + ).Returns(testResult); + this.mockTestMethodInfo.Setup(ds => ds.MethodInfo).Returns(methodInfo); + + TestFrameworkV2.TestMethodAttribute testMethodAttribute = new TestFrameworkV2.TestMethodAttribute(); + TestDataSource testDataSource = new TestDataSource(); + + TestFrameworkV2.TestResult[] result = testDataSource.RunDataDrivenTest(this.testContextImplementation, this.mockTestMethodInfo.Object, null, testMethodAttribute); + Assert.AreEqual(result[0].DatarowIndex, 0); + } + #region Dummy implementation - + public class DummyTestClass { private DesktopTestFrameworkV2.TestContext testContextInstance; diff --git a/test/UnitTests/MSTestAdapter.Tests/Execution/TestExecutionManagerTests.cs b/test/UnitTests/MSTestAdapter.Tests/Execution/TestExecutionManagerTests.cs index 9c25793a7a..bf93556e05 100644 --- a/test/UnitTests/MSTestAdapter.Tests/Execution/TestExecutionManagerTests.cs +++ b/test/UnitTests/MSTestAdapter.Tests/Execution/TestExecutionManagerTests.cs @@ -371,6 +371,17 @@ public void RunTestsForMultipleSourcesShouldRunEachTestJustOnce() #endregion + [TestMethodV1] + public void SendTestResultsShouldFillInDataRowIndexIfTestIsDataDriven() + { + var testCase = new TestCase("DummyTest", new System.Uri("executor://testExecutor"), Assembly.GetExecutingAssembly().Location); + UnitTestResult unitTestResult1 = new UnitTestResult() { DatarowIndex = 0, DisplayName = "DummyTest"}; + UnitTestResult unitTestResult2 = new UnitTestResult() { DatarowIndex = 1, DisplayName = "DummyTest" }; + this.TestExecutionManager.SendTestResults(testCase,new UnitTestResult[] {unitTestResult1,unitTestResult2},new DateTimeOffset(), new DateTimeOffset(), this.frameworkHandle); + Assert.AreEqual(frameworkHandle.TestDisplayNameList[0],"DummyTest (Data Row 0)"); + Assert.AreEqual(frameworkHandle.TestDisplayNameList[1],"DummyTest (Data Row 1)"); + } + #region private methods private TestCase GetTestCase(Type typeOfClass, string testName, bool ignore = false) @@ -486,13 +497,14 @@ private class TestableFrameworkHandle : IFrameworkHandle public readonly List ResultsList; public readonly List TestCaseStartList; public readonly List TestCaseEndList; - + public readonly List TestDisplayNameList; public TestableFrameworkHandle() { this.MessageList = new List(); this.ResultsList = new List(); this.TestCaseStartList = new List(); this.TestCaseEndList = new List(); + this.TestDisplayNameList = new List(); } public bool EnableShutdownAfterTestRun { get; set; } @@ -505,6 +517,7 @@ public void SendMessage(TestMessageLevel testMessageLevel, string message) public void RecordResult(TestResult testResult) { this.ResultsList.Add(testResult.ToString()); + this.TestDisplayNameList.Add(testResult.DisplayName); } public void RecordStart(TestCase testCase) diff --git a/test/UnitTests/MSTestAdapter.Tests/Execution/TestMethodRunnerTests.cs b/test/UnitTests/MSTestAdapter.Tests/Execution/TestMethodRunnerTests.cs index 4551cf418c..946658dbd0 100644 --- a/test/UnitTests/MSTestAdapter.Tests/Execution/TestMethodRunnerTests.cs +++ b/test/UnitTests/MSTestAdapter.Tests/Execution/TestMethodRunnerTests.cs @@ -349,7 +349,8 @@ public void ConvertTestResultToUnitTestResultForTestResultWithExceptionConvertsT public void ConvertTestResultToUnitTestResultForTestResultShouldSetLoggingDatatForConvertedUnitTestResults() { var timespan = new TimeSpan(); - var results = new[] { new UTF.TestResult() { DebugTrace = "debugTrace", DisplayName = "displayName", Duration = timespan, LogOutput = "logOutput", LogError = "logError"} }; + var results = new[] { new UTF.TestResult() { DebugTrace = "debugTrace", DisplayName = "displayName", Duration = timespan, LogOutput = "logOutput", + LogError = "logError", DatarowIndex = 1} }; var convertedResults = this.globalTestMethodRunner.ConvertTestResultToUnitTestResult(results); Assert.AreEqual("logOutput", convertedResults[0].StandardOut); @@ -357,6 +358,7 @@ public void ConvertTestResultToUnitTestResultForTestResultShouldSetLoggingDatatF Assert.AreEqual("displayName", convertedResults[0].DisplayName); Assert.AreEqual("debugTrace", convertedResults[0].DebugTrace); Assert.AreEqual(timespan, convertedResults[0].Duration); + Assert.AreEqual(1,convertedResults[0].DatarowIndex); } [TestMethodV1] From 39a04235d781cd1cf50e5149d304d2efed7ebba8 Mon Sep 17 00:00:00 2001 From: Jayarani Garg Date: Tue, 6 Sep 2016 18:08:07 +0530 Subject: [PATCH 5/7] Resolving merge conflicts --- .../Execution/TestExecutionManagerTests.cs | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/test/UnitTests/MSTestAdapter.Tests/Execution/TestExecutionManagerTests.cs b/test/UnitTests/MSTestAdapter.Tests/Execution/TestExecutionManagerTests.cs index cc3d90210e..0be93c73ea 100644 --- a/test/UnitTests/MSTestAdapter.Tests/Execution/TestExecutionManagerTests.cs +++ b/test/UnitTests/MSTestAdapter.Tests/Execution/TestExecutionManagerTests.cs @@ -610,23 +610,12 @@ internal override void ExecuteTests(IEnumerable tests, IRunContext run } } - internal class TestableTestExecutionManager : TestExecutionManager + internal override UnitTestDiscoverer GetUnitTestDiscoverer() { - internal override void ExecuteTests(IEnumerable tests, IRunContext runContext, - IFrameworkHandle frameworkHandle, bool isDeploymentDone) - { - if (this.ExecuteTestsWrapper != null) - { - this.ExecuteTestsWrapper.Invoke(tests, runContext, frameworkHandle, isDeploymentDone); - } - } - - internal override UnitTestDiscoverer GetUnitTestDiscoverer() - { - return new TestableUnitTestDiscoverer(); - } - - internal Action, IRunContext, IFrameworkHandle, bool> ExecuteTestsWrapper; + return new TestableUnitTestDiscoverer(); } - #endregion + + internal Action, IRunContext, IFrameworkHandle, bool> ExecuteTestsWrapper; + } + #endregion } From 97d3eb91fcbaee9e5462e640289fe824aac798e6 Mon Sep 17 00:00:00 2001 From: Jayarani Garg Date: Tue, 6 Sep 2016 19:39:14 +0530 Subject: [PATCH 6/7] Addressing PR comments --- src/Adapter/MSTestAdapter/ObjectModel/UnitTestResult.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Adapter/MSTestAdapter/ObjectModel/UnitTestResult.cs b/src/Adapter/MSTestAdapter/ObjectModel/UnitTestResult.cs index 2e5ee73b10..c194d09b95 100644 --- a/src/Adapter/MSTestAdapter/ObjectModel/UnitTestResult.cs +++ b/src/Adapter/MSTestAdapter/ObjectModel/UnitTestResult.cs @@ -34,11 +34,10 @@ internal UnitTestResult() /// Initializes a new instance of the class. /// /// The test failed exception. - internal UnitTestResult(TestFailedException testFailedException) + internal UnitTestResult(TestFailedException testFailedException):this() { this.Outcome = testFailedException.Outcome; this.ErrorMessage = testFailedException.Message; - DatarowIndex = -1; if (testFailedException.StackTraceInformation != null) { @@ -54,11 +53,10 @@ internal UnitTestResult(TestFailedException testFailedException) /// /// The outcome. /// The error message. - internal UnitTestResult(UnitTestOutcome outcome, string errorMessage) + internal UnitTestResult(UnitTestOutcome outcome, string errorMessage):this() { this.Outcome = outcome; this.ErrorMessage = errorMessage; - DatarowIndex = -1; } /// From 71e6eb3ea3189607d1f9d8cb2cb15b9ff80ca006 Mon Sep 17 00:00:00 2001 From: Jayarani Garg Date: Thu, 8 Sep 2016 18:56:37 +0530 Subject: [PATCH 7/7] Porting BugFix#260653: DataRowTests not getting appended by arguments --- .../vnext/DataTestMethodAttribute.cs | 5 ++ .../vnext/FrameworkMessages.Designer.cs | 19 +++-- .../vnext/FrameworkMessages.resx | 3 + .../DataTestMethodAttributeTests.cs | 75 +++++++++++++++++++ .../UnitTestFramework.Tests.csproj | 12 +++ .../UnitTestFramework.Tests/packages.config | 5 ++ 6 files changed, 114 insertions(+), 5 deletions(-) create mode 100644 test/UnitTests/UnitTestFramework.Tests/DataTestMethodAttributeTests.cs create mode 100644 test/UnitTests/UnitTestFramework.Tests/packages.config diff --git a/src/TestFramework/vnext/DataTestMethodAttribute.cs b/src/TestFramework/vnext/DataTestMethodAttribute.cs index a3dc013880..fa5b68e3d3 100644 --- a/src/TestFramework/vnext/DataTestMethodAttribute.cs +++ b/src/TestFramework/vnext/DataTestMethodAttribute.cs @@ -4,6 +4,7 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting { using System; using System.Collections.Generic; + using System.Globalization; #region DataRow @@ -52,6 +53,10 @@ internal static TestResult[] RunDataDrivenTest(ITestMethod testMethod, DataRowAt { result.DisplayName = dataRow.DisplayName; } + else + { + result.DisplayName = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.DataDrivenResultDisplayName, testMethod.TestMethodName, string.Join(",", dataRow.Data)); + } results.Add(result); } diff --git a/src/TestFramework/vnext/FrameworkMessages.Designer.cs b/src/TestFramework/vnext/FrameworkMessages.Designer.cs index 14b97c7b34..7d2ad0491e 100644 --- a/src/TestFramework/vnext/FrameworkMessages.Designer.cs +++ b/src/TestFramework/vnext/FrameworkMessages.Designer.cs @@ -1,7 +1,7 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.18010 +// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -11,7 +11,8 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting { using System; using System.Reflection; - + + /// /// A strongly-typed resource class, for looking up localized strings, etc. /// @@ -39,8 +40,7 @@ internal FrameworkMessages() { public static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - var assembly = typeof(FrameworkMessages).GetTypeInfo().Assembly; - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.VisualStudio.TestTools.UnitTesting.FrameworkMessages", assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.VisualStudio.TestTools.UnitTesting.FrameworkMessages", typeof(FrameworkMessages).GetTypeInfo().Assembly); resourceMan = temp; } return resourceMan; @@ -232,6 +232,15 @@ public static string ContainsFail { } } + /// + /// Looks up a localized string similar to {0} ({1}). + /// + public static string DataDrivenResultDisplayName { + get { + return ResourceManager.GetString("DataDrivenResultDisplayName", resourceCulture); + } + } + /// /// Looks up a localized string similar to Assert.Equals should not be used for Assertions. Please use Assert.AreEqual & overloads instead.. /// diff --git a/src/TestFramework/vnext/FrameworkMessages.resx b/src/TestFramework/vnext/FrameworkMessages.resx index 716f77a9d8..5350395f13 100644 --- a/src/TestFramework/vnext/FrameworkMessages.resx +++ b/src/TestFramework/vnext/FrameworkMessages.resx @@ -271,4 +271,7 @@ Stack Trace: {4} No DataRowAttribute specified. Atleast one DataRowAttribute is required with DataTestMethodAttribute. + + {0} ({1}) + \ No newline at end of file diff --git a/test/UnitTests/UnitTestFramework.Tests/DataTestMethodAttributeTests.cs b/test/UnitTests/UnitTestFramework.Tests/DataTestMethodAttributeTests.cs new file mode 100644 index 0000000000..0cf6a5f8fb --- /dev/null +++ b/test/UnitTests/UnitTestFramework.Tests/DataTestMethodAttributeTests.cs @@ -0,0 +1,75 @@ +// Copyright (c) Microsoft. All rights reserved. + +using System.Collections.Generic; + +namespace UnitTestFramework.Tests +{ + extern alias FrameworkV1; + extern alias FrameworkV2; + + using Moq; + using System; + + using TestFrameworkV1 = FrameworkV1.Microsoft.VisualStudio.TestTools.UnitTesting; + using TestFrameworkV2 = FrameworkV2.Microsoft.VisualStudio.TestTools.UnitTesting; + + /// + /// Tests for class DataTestMethodAttribute + /// + [TestFrameworkV1.TestClass] + public class DataTestMethodAttributeTests + { + private Mock testMethod; + + [TestFrameworkV1.TestInitialize] + public void TestInit() + { + this.testMethod = new Mock(); + } + + [TestFrameworkV1.TestMethod] + public void RunDataDrivenTestShouldFillInDisplayNameWithDataRowDisplayNameIfProvided() + { + int dummyIntData = 2; + string dummyStringData = "DummyString"; + TestFrameworkV2.DataRowAttribute dataRowAttribute = new TestFrameworkV2.DataRowAttribute(dummyIntData, + dummyStringData); + dataRowAttribute.DisplayName = "DataRowTestDisplayName"; + + TestFrameworkV2.TestResult testResult = new TestFrameworkV2.TestResult(); + + //Setup mocks. + this.testMethod.Setup(tm => tm.TestMethodName).Returns("DummyTestMethod"); + this.testMethod.Setup(tm => tm.Invoke(It.IsAny())).Returns(testResult); + + //Act. + TestFrameworkV2.TestResult[] results = + TestFrameworkV2.DataTestMethodAttribute.RunDataDrivenTest(this.testMethod.Object, + new TestFrameworkV2.DataRowAttribute[] {dataRowAttribute}); + + TestFrameworkV2.Assert.AreEqual(results[0].DisplayName, "DataRowTestDisplayName"); + } + + [TestFrameworkV1.TestMethod] + public void RunDataDrivenTestShouldFillInDisplayNameWithDataRowArgumentsIfNoDisplayNameIsProvided() + { + int dummyIntData = 2; + string dummyStringData = "DummyString"; + TestFrameworkV2.DataRowAttribute dataRowAttribute = new TestFrameworkV2.DataRowAttribute(dummyIntData, + dummyStringData); + + TestFrameworkV2.TestResult testResult = new TestFrameworkV2.TestResult(); + + //Setup mocks. + this.testMethod.Setup(tm => tm.TestMethodName).Returns("DummyTestMethod"); + this.testMethod.Setup(tm => tm.Invoke(It.IsAny())).Returns(testResult); + + //Act. + TestFrameworkV2.TestResult[] results = + TestFrameworkV2.DataTestMethodAttribute.RunDataDrivenTest(this.testMethod.Object, + new TestFrameworkV2.DataRowAttribute[] {dataRowAttribute}); + + TestFrameworkV2.Assert.AreEqual(results[0].DisplayName, "DummyTestMethod (2,DummyString)"); + } + } +} diff --git a/test/UnitTests/UnitTestFramework.Tests/UnitTestFramework.Tests.csproj b/test/UnitTests/UnitTestFramework.Tests/UnitTestFramework.Tests.csproj index 1bb039fbbe..47da3fc922 100644 --- a/test/UnitTests/UnitTestFramework.Tests/UnitTestFramework.Tests.csproj +++ b/test/UnitTests/UnitTestFramework.Tests/UnitTestFramework.Tests.csproj @@ -15,6 +15,14 @@ UnitTest + + $(TestFxRoot)packages\Castle.Core.3.3.3\lib\net45\Castle.Core.dll + True + + + $(TestFxRoot)packages\Moq.4.5.21\lib\net45\Moq.dll + True + @@ -34,10 +42,14 @@ + + + + \ No newline at end of file diff --git a/test/UnitTests/UnitTestFramework.Tests/packages.config b/test/UnitTests/UnitTestFramework.Tests/packages.config new file mode 100644 index 0000000000..fa422284e0 --- /dev/null +++ b/test/UnitTests/UnitTestFramework.Tests/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file