diff --git a/src/Microsoft.TestPlatform.Common/Logging/TestLoggerManager.cs b/src/Microsoft.TestPlatform.Common/Logging/TestLoggerManager.cs index f33df67691..e782366818 100644 --- a/src/Microsoft.TestPlatform.Common/Logging/TestLoggerManager.cs +++ b/src/Microsoft.TestPlatform.Common/Logging/TestLoggerManager.cs @@ -6,11 +6,14 @@ namespace Microsoft.VisualStudio.TestPlatform.Common.Logging using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Globalization; + using System.IO; using System.Linq; + using Microsoft.VisualStudio.TestPlatform.Common.Utilities; using CommonResources = Microsoft.VisualStudio.TestPlatform.Common.Resources; /// @@ -52,7 +55,7 @@ internal class TestLoggerManager : ITestDiscoveryEventsRegistrar, ITestRunEvents private TestLoggerExtensionManager testLoggerExtensionManager; private IDiscoveryRequest discoveryRequest; - + #endregion #region Constructor @@ -157,8 +160,7 @@ public void AddLogger(Uri uri, Dictionary parameters) } else { - // todo Read Output Directory from RunSettings - ((ITestLogger)logger.Value).Initialize(this.loggerEvents, null); + ((ITestLogger)logger.Value).Initialize(this.loggerEvents, this.GetResultsDirectory(RunSettingsManager.Instance.ActiveRunSettings)); } } catch (Exception e) @@ -181,7 +183,7 @@ public void AddLogger(Uri uri, Dictionary parameters) uri.OriginalString)); } } - + /// /// Tries to get uri of the logger corresponding to the friendly name. If no such logger exists return null. /// @@ -203,7 +205,7 @@ public bool TryGetUriFromFriendlyName(string friendlyName, out string loggerUri) loggerUri = null; return false; } - + /// /// Registers to receive events from the provided test run request. /// These events will then be broadcast to any registered loggers. @@ -239,7 +241,7 @@ public void RegisterDiscoveryEvents(IDiscoveryRequest discoveryRequest) this.discoveryRequest = discoveryRequest; discoveryRequest.OnDiscoveryMessage += this.DiscoveryMessageHandler; } - + /// /// Unregisters the events from the test run request. /// @@ -253,7 +255,7 @@ public void UnregisterTestRunEvents(ITestRunRequest testRunRequest) testRunRequest.OnRunCompletion -= this.TestRunCompleteHandler; this.runRequest.DataCollectionMessage -= this.DiscoveryMessageHandler; } - + /// /// Unregister the events from the discovery request. /// @@ -341,6 +343,33 @@ protected virtual void Dispose(bool disposing) #region Private Members + /// + /// Gets the test results directory. + /// + /// Test run settings. + /// Test results directory + internal string GetResultsDirectory(RunSettings runSettings) + { + string resultsDirectory = null; + if (runSettings != null) + { + try + { + RunConfiguration runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(runSettings.SettingsXml); + resultsDirectory = RunSettingsUtilities.GetTestResultsDirectory(runConfiguration); + } + catch (SettingsException se) + { + if (EqtTrace.IsErrorEnabled) + { + EqtTrace.Error("TestLoggerManager.GetResultsDirectory: Unable to get the test results directory: Error {0}", se); + } + } + } + + return resultsDirectory; + } + /// /// Populates user supplied and default logger parameters. /// diff --git a/src/Microsoft.TestPlatform.Common/Utilities/RunSettingsUtilities.cs b/src/Microsoft.TestPlatform.Common/Utilities/RunSettingsUtilities.cs index 30ffa10eaa..e7a31b8646 100644 --- a/src/Microsoft.TestPlatform.Common/Utilities/RunSettingsUtilities.cs +++ b/src/Microsoft.TestPlatform.Common/Utilities/RunSettingsUtilities.cs @@ -37,14 +37,8 @@ public static string GetTestResultsDirectory(RunConfiguration runConfiguration) string resultsDirectory = null; if (runConfiguration != null) { - if (!runConfiguration.ResultsDirectorySet) - { - resultsDirectory = null; - } - else - { - resultsDirectory = Environment.ExpandEnvironmentVariables(runConfiguration.ResultsDirectory); - } + // It will try to get path from runsettings, if not found then it will return default path. + resultsDirectory = Environment.ExpandEnvironmentVariables(runConfiguration.ResultsDirectory); } return resultsDirectory; diff --git a/src/Microsoft.TestPlatform.Extensions.TrxLogger/TrxLogger.cs b/src/Microsoft.TestPlatform.Extensions.TrxLogger/TrxLogger.cs index 33631a8607..a03da6c595 100644 --- a/src/Microsoft.TestPlatform.Extensions.TrxLogger/TrxLogger.cs +++ b/src/Microsoft.TestPlatform.Extensions.TrxLogger/TrxLogger.cs @@ -108,8 +108,6 @@ public void Initialize(TestLoggerEvents events, string testRunDirectory) events.TestResult += this.TestResultHandler; events.TestRunComplete += this.TestRunCompleteHandler; - // ToDo: - // currently we are getting null in testRunDirectory because reading run setting work has to be done TrxFileDirectory = testRunDirectory; this.InitializeInternal(); diff --git a/src/Microsoft.TestPlatform.ObjectModel/Constants.cs b/src/Microsoft.TestPlatform.ObjectModel/Constants.cs index d5d15aa24c..b2824d88f2 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Constants.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Constants.cs @@ -79,7 +79,7 @@ public static class Constants /// /// Default results directory. /// - public static readonly string DefaultResultsDirectory = Path.Combine("%Temp%", ResultsDirectoryName); + public static readonly string DefaultResultsDirectory = Path.Combine(Directory.GetCurrentDirectory(), ResultsDirectoryName); /// /// Default treatment of error from test adapters. diff --git a/src/Microsoft.TestPlatform.ObjectModel/RunSettings/RunConfiguration.cs b/src/Microsoft.TestPlatform.ObjectModel/RunSettings/RunConfiguration.cs index bb6975b86a..1c9fc7df63 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/RunSettings/RunConfiguration.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/RunSettings/RunConfiguration.cs @@ -96,7 +96,6 @@ public string ResultsDirectory set { this.resultsDirectory = value; - this.ResultsDirectorySet = true; } } @@ -240,15 +239,6 @@ public bool TestAdaptersPathsSet private set; } - /// - /// Gets a value indicating whether results directory is set. - /// - public bool ResultsDirectorySet - { - get; - private set; - } - /// /// Gets the binaries root. /// diff --git a/src/Microsoft.TestPlatform.VSIXCreator/CopyTrxToExtension.cmd b/src/Microsoft.TestPlatform.VSIXCreator/CopyTrxToExtension.cmd new file mode 100644 index 0000000000..30d7092f39 --- /dev/null +++ b/src/Microsoft.TestPlatform.VSIXCreator/CopyTrxToExtension.cmd @@ -0,0 +1,19 @@ +@IF NOT DEFINED _ECHO @ECHO OFF + +@ECHO. + +SET TPBINRELPATH=..\\..\\artifacts\\src\\Microsoft.TestPlatform.VSIXCreator\\bin\\Release + +IF EXIST "%TPBINRELPATH%" ( + IF EXIST "%TPBINRELPATH%\\net461\\win7-x64\\Microsoft.VisualStudio.TestPlatform.Extensions.TrxLogger.dll" ( + MOVE /Y "%TPBINRELPATH%\\net461\\win7-x64\\Microsoft.VisualStudio.TestPlatform.Extensions.TrxLogger.dll" "%TPBINRELPATH%\\net461\\win7-x64\\Extensions" + ) +) + +SET TPBINDEBUGPATH=..\\..\\artifacts\\src\\Microsoft.TestPlatform.VSIXCreator\\bin\\Debug + +IF EXIST "%TPBINDEBUGPATH%" ( + IF EXIST "%TPBINDEBUGPATH%\\net461\\win7-x64\\Microsoft.VisualStudio.TestPlatform.Extensions.TrxLogger.dll" ( + MOVE /Y "%TPBINDEBUGPATH%\\net461\\win7-x64\\Microsoft.VisualStudio.TestPlatform.Extensions.TrxLogger.dll" "%TPBINDEBUGPATH%\\net461\\win7-x64\\Extensions" + ) +) diff --git a/src/Microsoft.TestPlatform.VSIXCreator/project.json b/src/Microsoft.TestPlatform.VSIXCreator/project.json index d55301fcec..e8a98ffe3d 100644 --- a/src/Microsoft.TestPlatform.VSIXCreator/project.json +++ b/src/Microsoft.TestPlatform.VSIXCreator/project.json @@ -16,8 +16,8 @@ "scripts": { "precompile": "VSIXDelete.cmd", - "postcompile": [ "VSIXCreator.cmd" ] - }, + "postcompile": [ "CopyTrxToExtension.cmd", "VSIXCreator.cmd" ] + }, "frameworks": { "net461": { @@ -38,10 +38,10 @@ "testhost": "15.0.0-*", "testhost.x86": "15.0.0-*", "vstest.console": "15.0.0-*", - "Microsoft.Internal.TestPlatform.Extensions": { "type": "build", - "version": "15.0.0" - } + "version": "15.0.0" + }, + "Microsoft.TestPlatform.Extensions.TrxLogger": "15.0.0-*" } } \ No newline at end of file diff --git a/test/Microsoft.TestPlatform.Client.UnitTests/project.json b/test/Microsoft.TestPlatform.Client.UnitTests/project.json index 57f3d781f1..fcbed5caf2 100644 --- a/test/Microsoft.TestPlatform.Client.UnitTests/project.json +++ b/test/Microsoft.TestPlatform.Client.UnitTests/project.json @@ -18,7 +18,7 @@ }, "MSTest.TestFramework": "1.0.0-preview", "moq.netcore": "4.4.0-beta8", - "System.Diagnostics.TraceSource": "4.0.0-rc2-24015", + "System.Diagnostics.TraceSource": "4.0.0", "Microsoft.TestPlatform.Client": "15.0.0-*" }, diff --git a/test/Microsoft.TestPlatform.Common.UnitTests/Logging/TestLoggerManagerTests.cs b/test/Microsoft.TestPlatform.Common.UnitTests/Logging/TestLoggerManagerTests.cs index 5e1b8bb8d0..51e8204f95 100644 --- a/test/Microsoft.TestPlatform.Common.UnitTests/Logging/TestLoggerManagerTests.cs +++ b/test/Microsoft.TestPlatform.Common.UnitTests/Logging/TestLoggerManagerTests.cs @@ -2,6 +2,7 @@ namespace TestPlatform.Common.UnitTests.Logging { + using Microsoft.VisualStudio.TestPlatform.Common; using Microsoft.VisualStudio.TestPlatform.Common.Logging; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; @@ -54,6 +55,52 @@ public void TryGetUriFromFriendlyNameShouldNotReturnUriIfLoggerIsNotAdded() Assert.IsNull(uri); } + [TestMethod] + public void GetResultsDirectoryShouldReturnNullIfRunSettingsIsNull() + { + string result = TestLoggerManager.Instance.GetResultsDirectory(null); + Assert.AreEqual(null, result); + } + + [TestMethod] + public void GetResultsDirectoryShouldReadResultsDirectoryFromSettingsIfSpecified() + { + string runSettingsXml = @" + + + 0 + DummyTestResultsFolder + x64 + Framework45 + + "; + + RunSettings runsettings = new RunSettings(); + runsettings.LoadSettingsXml(runSettingsXml); + + string result = TestLoggerManager.Instance.GetResultsDirectory(runsettings); + Assert.AreEqual(string.Compare("DummyTestResultsFolder", result), 0); + } + + [TestMethod] + public void GetResultsDirectoryShouldReturnDefaultPathIfResultsDirectoryIsNotProvidedInRunSettings() + { + string runSettingsXml = @" + + + 0 + x64 + Framework45 + + "; + + RunSettings runsettings = new RunSettings(); + runsettings.LoadSettingsXml(runSettingsXml); + + string result = TestLoggerManager.Instance.GetResultsDirectory(runsettings); + Assert.AreEqual(string.Compare(Constants.DefaultResultsDirectory, result), 0); + } + [TestMethod] public void TestRunRequestRaiseShouldInvokeTestRunMessageHandlerOfLoggersIfRegistered() { diff --git a/test/Microsoft.TestPlatform.Common.UnitTests/project.json b/test/Microsoft.TestPlatform.Common.UnitTests/project.json index b12ef7b3dc..ee3e89f978 100644 --- a/test/Microsoft.TestPlatform.Common.UnitTests/project.json +++ b/test/Microsoft.TestPlatform.Common.UnitTests/project.json @@ -18,7 +18,7 @@ }, "MSTest.TestFramework": "1.0.0-preview", "moq.netcore": "4.4.0-beta8", - "System.Diagnostics.TraceSource": "4.0.0-rc2-24015", + "System.Diagnostics.TraceSource": "4.0.0", "Microsoft.TestPlatform.Common": "15.0.0-*" }, diff --git a/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/project.json b/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/project.json index eca8f0460b..1e8f6a5df2 100644 --- a/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/project.json +++ b/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/project.json @@ -18,7 +18,7 @@ }, "MSTest.TestFramework": "1.0.0-preview", "moq.netcore": "4.4.0-beta8", - "System.Diagnostics.TraceSource": "4.0.0-rc2-24015", + "System.Diagnostics.TraceSource": "4.0.0", "Microsoft.TestPlatform.CommunicationUtilities": "15.0.0-*" }, diff --git a/test/Microsoft.TestPlatform.CoreUtilities.UnitTests/project.json b/test/Microsoft.TestPlatform.CoreUtilities.UnitTests/project.json index 6900b217a6..794831b6b5 100644 --- a/test/Microsoft.TestPlatform.CoreUtilities.UnitTests/project.json +++ b/test/Microsoft.TestPlatform.CoreUtilities.UnitTests/project.json @@ -18,7 +18,7 @@ }, "MSTest.TestFramework": "1.0.0-preview", "moq.netcore": "4.4.0-beta8", - "System.Diagnostics.TraceSource": "4.0.0-rc2-24015", + "System.Diagnostics.TraceSource": "4.0.0", "Microsoft.TestPlatform.CoreUtilities": "15.0.0-*" }, diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/project.json b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/project.json index 35ebd037c8..bc857e53e1 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/project.json +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/project.json @@ -18,7 +18,7 @@ }, "MSTest.TestFramework": "1.0.0-preview", "moq.netcore": "4.4.0-beta8", - "System.Diagnostics.TraceSource": "4.0.0-rc2-24015", + "System.Diagnostics.TraceSource": "4.0.0", "Microsoft.TestPlatform.CrossPlatEngine": "15.0.0-*", "Microsoft.TestPlatform.ObjectModel": "15.0.0-*", "Microsoft.TestPlatform.Common": "15.0.0-*", diff --git a/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/project.json b/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/project.json index eac7795cc8..667f1eac59 100644 --- a/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/project.json +++ b/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/project.json @@ -18,7 +18,7 @@ }, "MSTest.TestFramework": "1.0.0-preview", "moq.netcore": "4.4.0-beta8", - "System.Diagnostics.TraceSource": "4.0.0-rc2-24015", + "System.Diagnostics.TraceSource": "4.0.0", "Microsoft.TestPlatform.Client": "15.0.0-*", "Microsoft.TestPlatform.Extensions.TrxLogger": "15.0.0-*", "Microsoft.TestPlatform.ObjectModel": "15.0.0-*" diff --git a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/project.json b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/project.json index 0a55d85444..8cb962b6aa 100644 --- a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/project.json +++ b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/project.json @@ -18,7 +18,7 @@ }, "MSTest.TestFramework": "1.0.0-preview", "moq.netcore": "4.4.0-beta8", - "System.Diagnostics.TraceSource": "4.0.0-rc2-24015", + "System.Diagnostics.TraceSource": "4.0.0", "Microsoft.TestPlatform.ObjectModel": "15.0.0-*" }, diff --git a/test/Microsoft.TestPlatform.VsTestConsole.TranslationLayer.UnitTests/project.json b/test/Microsoft.TestPlatform.VsTestConsole.TranslationLayer.UnitTests/project.json index cf5e667806..4e35eb1074 100644 --- a/test/Microsoft.TestPlatform.VsTestConsole.TranslationLayer.UnitTests/project.json +++ b/test/Microsoft.TestPlatform.VsTestConsole.TranslationLayer.UnitTests/project.json @@ -18,7 +18,7 @@ }, "MSTest.TestFramework": "1.0.0-preview", "moq.netcore": "4.4.0-beta8", - "System.Diagnostics.TraceSource": "4.0.0-rc2-24015", + "System.Diagnostics.TraceSource": "4.0.0", "Microsoft.TestPlatform.VsTestConsole.TranslationLayer": "15.0.0-*", "Microsoft.TestPlatform.CommunicationUtilities": "15.0.0-*", "Microsoft.TestPlatform.ObjectModel": "15.0.0-*" diff --git a/test/datacollector.x86.UnitTests/project.json b/test/datacollector.x86.UnitTests/project.json index f023a24637..12b94d190a 100644 --- a/test/datacollector.x86.UnitTests/project.json +++ b/test/datacollector.x86.UnitTests/project.json @@ -18,7 +18,7 @@ }, "MSTest.TestFramework": "1.0.0-preview", "moq.netcore": "4.4.0-beta8", - "System.Diagnostics.TraceSource": "4.0.0-rc2-24015", + "System.Diagnostics.TraceSource": "4.0.0", "datacollector": "15.0.0-*" }, diff --git a/test/testhost.UnitTests/project.json b/test/testhost.UnitTests/project.json index f66c69f3ad..2d4cd606ad 100644 --- a/test/testhost.UnitTests/project.json +++ b/test/testhost.UnitTests/project.json @@ -18,7 +18,7 @@ }, "MSTest.TestFramework": "1.0.0-preview", "moq.netcore": "4.4.0-beta8", - "System.Diagnostics.TraceSource": "4.0.0-rc2-24015" + "System.Diagnostics.TraceSource": "4.0.0" }, "frameworks": { diff --git a/test/vstest.console.UnitTests/project.json b/test/vstest.console.UnitTests/project.json index 9a5054f7ac..3c44f8706a 100644 --- a/test/vstest.console.UnitTests/project.json +++ b/test/vstest.console.UnitTests/project.json @@ -18,7 +18,7 @@ }, "MSTest.TestFramework": "1.0.0-preview", "moq.netcore": "4.4.0-beta8", - "System.Diagnostics.TraceSource": "4.0.0-rc2-24015", + "System.Diagnostics.TraceSource": "4.0.0", "vstest.console": "15.0.0-*", "Microsoft.TestPlatform.Client": "15.0.0-*" },