diff --git a/scripts/test.ps1 b/scripts/test.ps1 new file mode 100644 index 0000000000..8a3cd05390 --- /dev/null +++ b/scripts/test.ps1 @@ -0,0 +1,172 @@ +# Copyright (c) Microsoft. All rights reserved. +# Build script for Test Platform. + +[CmdletBinding()] +Param( + [Parameter(Mandatory=$false)] + [ValidateSet("Debug", "Release")] + [Alias("c")] + [System.String] $Configuration = "Debug", + + # Only test sources matching the pattern are run. + # Use End2End to run E2E tests. Or to run any one assembly tests, use the + # assembly name. E.g. test -p Microsoft.TestPlatform.CoreUtilities.UnitTests + [Parameter(Mandatory=$false)] + [Alias("p")] + [System.String] $Pattern = "Unit", + + # Stop test run on first failure + [Parameter(Mandatory=$false)] + [Alias("ff")] + [Switch] $FailFast = $false +) + +$ErrorActionPreference = "Stop" + +# +# Variables +# +Write-Verbose "Setup environment variables." +$env:TP_ROOT_DIR = (Get-Item (Split-Path $MyInvocation.MyCommand.Path)).Parent.FullName +$env:TP_TOOLS_DIR = Join-Path $env:TP_ROOT_DIR "tools" +$env:TP_PACKAGES_DIR = Join-Path $env:TP_ROOT_DIR "packages" +$env:TP_OUT_DIR = Join-Path $env:TP_ROOT_DIR "artifacts" + +# +# Dotnet configuration +# +# Disable first run since we want to control all package sources +Write-Verbose "Setup dotnet configuration." +$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1 +# Dotnet build doesn't support --packages yet. See https://github.com/dotnet/cli/issues/2712 +$env:NUGET_PACKAGES = $env:TP_PACKAGES_DIR + +# +# Test configuration +# +# Folders to build. TODO move to props +Write-Verbose "Setup build configuration." +$Script:TPT_Configuration = $Configuration +$Script:TPT_SourceFolders = @("test") +$Script:TPT_TargetFramework = "net46" +$Script:TPT_TargetRuntime = "win7-x64" +$Script:TPT_SkipProjects = @("Microsoft.TestPlatform.CoreUtilities.UnitTests") +$Script:TPT_Pattern = $Pattern +$Script:TPT_FailFast = $FailFast + +function Write-Log ([string] $message) +{ + $currentColor = $Host.UI.RawUI.ForegroundColor + $Host.UI.RawUI.ForegroundColor = "Green" + if ($message) + { + Write-Output "... $message" + } + $Host.UI.RawUI.ForegroundColor = $currentColor +} + +function Write-VerboseLog([string] $message) +{ + Write-Verbose $message +} + +function Invoke-Test +{ + $timer = Start-Timer + Write-Log "Invoke-Test: Start test." + $dotnetExe = Get-DotNetPath + + foreach ($src in $Script:TPT_SourceFolders) { + # Invoke test for each project.json since we want a custom output + # path. + $vstestConsolePath = Join-Path (Get-PackageDirectory) "vstest.console.exe" + if (!(Test-Path $vstestConsolePath)) { + Write-Log "Unable to find vstest.console.exe at $vstestConsolePath. Did you run build.cmd?" + Write-Error "Test aborted." + } + + foreach ($fx in $Script:TPT_TargetFramework) { + Get-ChildItem -Recurse -Path $src -Include "project.json" | ForEach-Object { + Write-Log ".. Test: Source: $_" + + # Tests are only built for x86 at the moment, though we don't have architecture requirement + $testContainerName = $_.Directory.Name + $testOutputPath = Join-Path $_.Directory.FullName "bin/$($Script:TPT_Configuration)/$($Script:TPT_TargetFramework)/win7-x86" + $testContainerPath = Join-Path $testOutputPath "$($testContainerName).dll" + + if ($Script:TPT_SkipProjects.Contains($testContainerName)) { + Write-Log ".. . $testContainerName is in skipped test list." + } elseif (!($testContainerName -match $Script:TPT_Pattern)) { + Write-Log ".. . $testContainerName doesn't match test container pattern '$($Script:TPT_Pattern)'. Skipped from run." + } else { + Write-Verbose "vstest.console.exe $testContainerPath /testAdapterPath:$testOutputPath" + $output = & $vstestConsolePath $testContainerPath /testAdapterPath:"$testOutputPath" + + #Write-Verbose "$dotnetExe test $_ --configuration $Configuration" + #& $dotnetExe test $_ --configuration $Configuration + + if ($output[-2].Contains("Test Run Successful.")) { + Write-Log ".. . $($output[-3])" + } else { + Write-Log ".. . $($output[-2])" + Write-Log ".. . Failed tests:" + Write-Log ".. . $($output -match '^Failed')" + + if ($Script:TPT_FailFast) { + Write-Log ".. Stop execution since fail fast is enabled." + continue + } + } + } + + Write-Log ".. Test: Complete." + } + } + #Write-Verbose "$dotnetExe test $src\**\project.json --configuration $Configuration" + #& $dotnetExe test $_ $src\**\project.json --configuration $Configuration + } + + Write-Log "Invoke-Test: Complete. {$(Get-ElapsedTime($timer))}" +} + +# +# Helper functions +# +function Get-DotNetPath +{ + $dotnetPath = Join-Path $env:TP_TOOLS_DIR "dotnet\dotnet.exe" + if (-not (Test-Path $dotnetPath)) { + Write-Error "Dotnet.exe not found at $dotnetPath. Did the dotnet cli installation succeed?" + } + + return $dotnetPath +} + +function Get-PackageDirectory +{ + return $(Join-Path $env:TP_OUT_DIR "$($Script:TPT_Configuration)\$($Script:TPT_TargetFramework)\$($Script:TPT_TargetRuntime)") +} + +function Start-Timer +{ + return [System.Diagnostics.Stopwatch]::StartNew() +} + +function Get-ElapsedTime([System.Diagnostics.Stopwatch] $timer) +{ + $timer.Stop() + return $timer.Elapsed +} + +# Execute build +$timer = Start-Timer +Write-Log "Build started: args = '$args'" +Write-Log "Test platform environment variables: " +Get-ChildItem env: | Where-Object -FilterScript { $_.Name.StartsWith("TP_") } | Format-Table + +Write-Log "Test run configuration: " +Get-Variable | Where-Object -FilterScript { $_.Name.StartsWith("TPT_") } | Format-Table + +Invoke-Test + +Write-Log "Build complete. {$(Get-ElapsedTime($timer))}" diff --git a/src/Microsoft.TestPlatform.Common/Logging/TestLoggerManager.cs b/src/Microsoft.TestPlatform.Common/Logging/TestLoggerManager.cs index f33df67691..5f75124fae 100644 --- a/src/Microsoft.TestPlatform.Common/Logging/TestLoggerManager.cs +++ b/src/Microsoft.TestPlatform.Common/Logging/TestLoggerManager.cs @@ -86,6 +86,7 @@ public static TestLoggerManager Instance } return testLoggerManager; } + protected set { testLoggerManager = value; diff --git a/src/Microsoft.TestPlatform.Extensions.TrxLogger/project.json b/src/Microsoft.TestPlatform.Extensions.TrxLogger/project.json index 739e003559..519fa6fec9 100644 --- a/src/Microsoft.TestPlatform.Extensions.TrxLogger/project.json +++ b/src/Microsoft.TestPlatform.Extensions.TrxLogger/project.json @@ -8,7 +8,6 @@ }, "dependencies": { - "Microsoft.TestPlatform.ObjectModel": "15.0.0-*", "Microsoft.TestPlatform.CoreUtilities": "15.0.0-*" }, diff --git a/src/vstest.console/Internal/ConsoleLogger.cs b/src/vstest.console/Internal/ConsoleLogger.cs index 5a636886b0..e928d6021f 100644 --- a/src/vstest.console/Internal/ConsoleLogger.cs +++ b/src/vstest.console/Internal/ConsoleLogger.cs @@ -37,8 +37,6 @@ internal class ConsoleLogger : ITestLogger #region Fields - private static IOutput output; - private TestOutcome testOutcome = TestOutcome.None; private int testsTotal = 0; private int testsPassed = 0; @@ -62,7 +60,7 @@ public ConsoleLogger() /// internal ConsoleLogger(IOutput output) { - ConsoleLogger.output = output; + ConsoleLogger.Output = output; } #endregion @@ -74,10 +72,8 @@ internal ConsoleLogger(IOutput output) /// Protected so this can be detoured for testing purposes. protected static IOutput Output { - get - { - return output; - } + get; + private set; } #endregion @@ -95,9 +91,9 @@ public void Initialize(TestLoggerEvents events, string testRunDirectory) throw new ArgumentNullException("events"); } - if (output == null) + if (ConsoleLogger.Output == null) { - output = ConsoleOutput.Instance; + ConsoleLogger.Output = ConsoleOutput.Instance; } // Register for the events. diff --git a/test.cmd b/test.cmd new file mode 100644 index 0000000000..67c2c09687 --- /dev/null +++ b/test.cmd @@ -0,0 +1,6 @@ +@echo off + +REM Copyright (c) Microsoft. All rights reserved. + +powershell -NoProfile -NoLogo -Command "%~dp0scripts\test.ps1 %*; exit $LastExitCode;" +if %errorlevel% neq 0 exit /b %errorlevel% diff --git a/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeTestHostLauncherFactoryTests.cs b/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeTestHostLauncherFactoryTests.cs index 7a61192f6e..86e2b47407 100644 --- a/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeTestHostLauncherFactoryTests.cs +++ b/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeTestHostLauncherFactoryTests.cs @@ -2,9 +2,12 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.UnitTests.DesignMode { - using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; - using Microsoft.VisualStudio.TestPlatform.Client.DesignMode; using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; using Microsoft.VisualStudio.TestTools.UnitTesting; - using Moq; + using Microsoft.VisualStudio.TestPlatform.Client.DesignMode; + using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + using Moq; [TestClass] public class DesignModeTestHostLauncherFactoryTests @@ -13,32 +16,20 @@ public class DesignModeTestHostLauncherFactoryTests public void DesignModeTestHostFactoryShouldReturnNonDebugLauncherIfDebuggingDisabled() { var mockDesignModeClient = new Mock(); - var testRunRequestPayload = new TestRunRequestPayload() { DebuggingEnabled = false }; + var testRunRequestPayload = new TestRunRequestPayload { DebuggingEnabled = false }; var launcher = DesignModeTestHostLauncherFactory.GetCustomHostLauncherForTestRun(mockDesignModeClient.Object, testRunRequestPayload); Assert.IsFalse(launcher.IsDebug, "Factory must not return debug launcher if debugging is disabled."); - - var testProcessStartInfo = new TestProcessStartInfo(); - - launcher.LaunchTestHost(testProcessStartInfo); - - mockDesignModeClient.Verify(md => md.LaunchCustomHost(testProcessStartInfo), Times.Once, "Launcher should use provided design mode client"); } [TestMethod] public void DesignModeTestHostFactoryShouldReturnDebugLauncherIfDebuggingEnabled() { var mockDesignModeClient = new Mock(); - var testRunRequestPayload = new TestRunRequestPayload() { DebuggingEnabled = true }; + var testRunRequestPayload = new TestRunRequestPayload { DebuggingEnabled = true }; var launcher = DesignModeTestHostLauncherFactory.GetCustomHostLauncherForTestRun(mockDesignModeClient.Object, testRunRequestPayload); Assert.IsTrue(launcher.IsDebug, "Factory must not return debug launcher if debugging is disabled."); - - var testProcessStartInfo = new TestProcessStartInfo(); - - launcher.LaunchTestHost(testProcessStartInfo); - - mockDesignModeClient.Verify(md => md.LaunchCustomHost(testProcessStartInfo), Times.Once, "Launcher should use provided design mode client"); } } } diff --git a/test/Microsoft.TestPlatform.Client.UnitTests/project.json b/test/Microsoft.TestPlatform.Client.UnitTests/project.json index 57f3d781f1..00245336a9 100644 --- a/test/Microsoft.TestPlatform.Client.UnitTests/project.json +++ b/test/Microsoft.TestPlatform.Client.UnitTests/project.json @@ -8,15 +8,11 @@ }, "dependencies": { - "Microsoft.NETCore.App": { - "type": "platform", - "version": "1.0.0" - }, - "dotnet-test-mstest": { - "version": "1.0.1-preview", + "MSTest.TestFramework": "1.0.0-preview", + "MSTest.TestAdapter": { + "version": "1.0.3-preview", "exclude": "compile" }, - "MSTest.TestFramework": "1.0.0-preview", "moq.netcore": "4.4.0-beta8", "System.Diagnostics.TraceSource": "4.0.0-rc2-24015", "Microsoft.TestPlatform.Client": "15.0.0-*" @@ -27,9 +23,26 @@ "imports": [ "dnxcore50", "portable-net45+win8" - ] - } + ], + + "dependencies": { + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.0.0" + }, + "dotnet-test-mstest": { + "version": "1.0.1-preview", + "exclude": "compile" + } + } + }, + + "net46": { + "frameworkAssemblies": { + "System.Runtime": "" + } + } }, "testRunner": "mstest" -} +} \ No newline at end of file diff --git a/test/Microsoft.TestPlatform.Common.UnitTests/ExtensionFramework/TestPluginCacheTests.cs b/test/Microsoft.TestPlatform.Common.UnitTests/ExtensionFramework/TestPluginCacheTests.cs index 348940567a..8f33967857 100644 --- a/test/Microsoft.TestPlatform.Common.UnitTests/ExtensionFramework/TestPluginCacheTests.cs +++ b/test/Microsoft.TestPlatform.Common.UnitTests/ExtensionFramework/TestPluginCacheTests.cs @@ -134,12 +134,18 @@ public void UpdateAdditionalExtensionsShouldResetExtensionsDiscoveredFlag() [TestMethod] public void GetDefaultResolutionPathsShouldReturnCurrentDirectoryByDefault() { - var resolutionPaths = TestPluginCache.Instance.GetDefaultResolutionPaths(); - var currentDirectory = Path.GetDirectoryName(typeof(TestPluginCache).GetTypeInfo().Assembly.Location); + var defaultExtensionsDirectory = Path.Combine(currentDirectory, "Extensions"); + var expectedDirectories = new List { currentDirectory }; + if (Directory.Exists(defaultExtensionsDirectory)) + { + expectedDirectories.Add(defaultExtensionsDirectory); + } + + var resolutionPaths = TestPluginCache.Instance.GetDefaultResolutionPaths(); Assert.IsNotNull(resolutionPaths); - CollectionAssert.AreEqual(new List { currentDirectory }, resolutionPaths.ToList()); + CollectionAssert.AreEqual(expectedDirectories, resolutionPaths.ToList()); } [TestMethod] diff --git a/test/Microsoft.TestPlatform.Common.UnitTests/project.json b/test/Microsoft.TestPlatform.Common.UnitTests/project.json index b12ef7b3dc..7abef37a51 100644 --- a/test/Microsoft.TestPlatform.Common.UnitTests/project.json +++ b/test/Microsoft.TestPlatform.Common.UnitTests/project.json @@ -8,15 +8,11 @@ }, "dependencies": { - "Microsoft.NETCore.App": { - "type": "platform", - "version": "1.0.0" - }, - "dotnet-test-mstest": { - "version": "1.0.1-preview", + "MSTest.TestFramework": "1.0.0-preview", + "MSTest.TestAdapter": { + "version": "1.0.3-preview", "exclude": "compile" }, - "MSTest.TestFramework": "1.0.0-preview", "moq.netcore": "4.4.0-beta8", "System.Diagnostics.TraceSource": "4.0.0-rc2-24015", "Microsoft.TestPlatform.Common": "15.0.0-*" @@ -27,9 +23,26 @@ "imports": [ "dnxcore50", "portable-net45+win8" - ] - } + ], + + "dependencies": { + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.0.0" + }, + "dotnet-test-mstest": { + "version": "1.0.1-preview", + "exclude": "compile" + } + } + }, + + "net46": { + "frameworkAssemblies": { + "System.Runtime": "" + } + } }, "testRunner": "mstest" -} +} \ No newline at end of file diff --git a/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/project.json b/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/project.json index eca8f0460b..565df3a692 100644 --- a/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/project.json +++ b/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/project.json @@ -8,15 +8,11 @@ }, "dependencies": { - "Microsoft.NETCore.App": { - "type": "platform", - "version": "1.0.0" - }, - "dotnet-test-mstest": { - "version": "1.0.1-preview", + "MSTest.TestFramework": "1.0.0-preview", + "MSTest.TestAdapter": { + "version": "1.0.3-preview", "exclude": "compile" }, - "MSTest.TestFramework": "1.0.0-preview", "moq.netcore": "4.4.0-beta8", "System.Diagnostics.TraceSource": "4.0.0-rc2-24015", "Microsoft.TestPlatform.CommunicationUtilities": "15.0.0-*" @@ -27,8 +23,25 @@ "imports": [ "dnxcore50", "portable-net45+win8" - ] - } + ], + + "dependencies": { + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.0.0" + }, + "dotnet-test-mstest": { + "version": "1.0.1-preview", + "exclude": "compile" + } + } + }, + + "net46": { + "frameworkAssemblies": { + "System.Runtime": "" + } + } }, "testRunner": "mstest" diff --git a/test/Microsoft.TestPlatform.CoreUtilities.UnitTests/project.json b/test/Microsoft.TestPlatform.CoreUtilities.UnitTests/project.json index 6900b217a6..f042dc1712 100644 --- a/test/Microsoft.TestPlatform.CoreUtilities.UnitTests/project.json +++ b/test/Microsoft.TestPlatform.CoreUtilities.UnitTests/project.json @@ -8,15 +8,11 @@ }, "dependencies": { - "Microsoft.NETCore.App": { - "type": "platform", - "version": "1.0.0" - }, - "dotnet-test-mstest": { - "version": "1.0.1-preview", + "MSTest.TestFramework": "1.0.0-preview", + "MSTest.TestAdapter": { + "version": "1.0.3-preview", "exclude": "compile" }, - "MSTest.TestFramework": "1.0.0-preview", "moq.netcore": "4.4.0-beta8", "System.Diagnostics.TraceSource": "4.0.0-rc2-24015", "Microsoft.TestPlatform.CoreUtilities": "15.0.0-*" @@ -27,8 +23,25 @@ "imports": [ "dnxcore50", "portable-net45+win8" - ] - } + ], + + "dependencies": { + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.0.0" + }, + "dotnet-test-mstest": { + "version": "1.0.1-preview", + "exclude": "compile" + } + } + }, + + "net46": { + "frameworkAssemblies": { + "System.Runtime": "" + } + } }, "testRunner": "mstest" diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Execution/InProcDataCollectionExtensionManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Execution/InProcDataCollectionExtensionManagerTests.cs index 6684da3607..b0dcc0e82d 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Execution/InProcDataCollectionExtensionManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Execution/InProcDataCollectionExtensionManagerTests.cs @@ -4,7 +4,6 @@ namespace TestPlatform.CrossPlatEngine.UnitTests.Execution using System; using System.Collections.ObjectModel; using System.Reflection; - using System.Runtime.Loader; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.EventHandlers; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution; diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Hosting/DefaultTestHostManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Hosting/DefaultTestHostManagerTests.cs index 72efa73c79..b818d589a5 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Hosting/DefaultTestHostManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Hosting/DefaultTestHostManagerTests.cs @@ -49,13 +49,8 @@ public void ConstructorShouldSetX86ProcessForX86Architecture() }; this.testHostManager.LaunchTestHost(new Dictionary(), new List()); - - var expectedProcessPath = - Path.Combine( - Path.GetDirectoryName(typeof(DefaultTestHostManagerTests).GetTypeInfo().Assembly.Location), - "testhost.x86.exe"); - Assert.AreEqual(expectedProcessPath, processPath); + StringAssert.EndsWith(processPath, "testhost.x86.exe"); Assert.AreEqual(1, times); } @@ -77,12 +72,7 @@ public void ConstructorShouldSetX64ProcessForX64Architecture() this.testHostManager.LaunchTestHost(new Dictionary(), new List()); - var expectedProcessPath = - Path.Combine( - Path.GetDirectoryName(typeof(DefaultTestHostManagerTests).GetTypeInfo().Assembly.Location), - "testhost.exe"); - - Assert.AreEqual(expectedProcessPath, processPath); + StringAssert.EndsWith(processPath, "testhost.exe"); Assert.AreEqual(1, times); } diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/project.json b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/project.json index 35ebd037c8..9706aedb3e 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/project.json +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/project.json @@ -8,15 +8,11 @@ }, "dependencies": { - "Microsoft.NETCore.App": { - "type": "platform", - "version": "1.0.0" - }, - "dotnet-test-mstest": { - "version": "1.0.1-preview", + "MSTest.TestFramework": "1.0.0-preview", + "MSTest.TestAdapter": { + "version": "1.0.3-preview", "exclude": "compile" }, - "MSTest.TestFramework": "1.0.0-preview", "moq.netcore": "4.4.0-beta8", "System.Diagnostics.TraceSource": "4.0.0-rc2-24015", "Microsoft.TestPlatform.CrossPlatEngine": "15.0.0-*", @@ -30,8 +26,25 @@ "imports": [ "dnxcore50", "portable-net45+win8" - ] - } + ], + + "dependencies": { + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.0.0" + }, + "dotnet-test-mstest": { + "version": "1.0.1-preview", + "exclude": "compile" + } + } + }, + + "net46": { + "frameworkAssemblies": { + "System.Runtime": "" + } + } }, "testRunner": "mstest" diff --git a/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/project.json b/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/project.json index eac7795cc8..19191fe6cb 100644 --- a/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/project.json +++ b/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/project.json @@ -8,20 +8,16 @@ }, "dependencies": { - "Microsoft.NETCore.App": { - "type": "platform", - "version": "1.0.0" - }, - "dotnet-test-mstest": { - "version": "1.0.1-preview", + "MSTest.TestFramework": "1.0.0-preview", + "MSTest.TestAdapter.Dotnet": { + "version": "1.0.0-preview", "exclude": "compile" }, - "MSTest.TestFramework": "1.0.0-preview", - "moq.netcore": "4.4.0-beta8", "System.Diagnostics.TraceSource": "4.0.0-rc2-24015", "Microsoft.TestPlatform.Client": "15.0.0-*", "Microsoft.TestPlatform.Extensions.TrxLogger": "15.0.0-*", - "Microsoft.TestPlatform.ObjectModel": "15.0.0-*" + "Microsoft.TestPlatform.ObjectModel": "15.0.0-*", + "moq.netcore": "4.4.0-beta8" }, "frameworks": { @@ -29,8 +25,25 @@ "imports": [ "dnxcore50", "portable-net45+win8" - ] - } + ], + + "dependencies": { + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.0.0" + }, + "dotnet-test-mstest": { + "version": "1.0.1-preview", + "exclude": "compile" + } + } + }, + + "net46": { + "frameworkAssemblies": { + "System.Runtime": "" + } + } }, "testRunner": "mstest" diff --git a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/project.json b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/project.json index 0a55d85444..158a7b0b59 100644 --- a/test/Microsoft.TestPlatform.ObjectModel.UnitTests/project.json +++ b/test/Microsoft.TestPlatform.ObjectModel.UnitTests/project.json @@ -8,16 +8,11 @@ }, "dependencies": { - "Microsoft.NETCore.App": { - "type": "platform", - "version": "1.0.0" - }, - "dotnet-test-mstest": { - "version": "1.0.1-preview", + "MSTest.TestFramework": "1.0.0-preview", + "MSTest.TestAdapter": { + "version": "1.0.3-preview", "exclude": "compile" }, - "MSTest.TestFramework": "1.0.0-preview", - "moq.netcore": "4.4.0-beta8", "System.Diagnostics.TraceSource": "4.0.0-rc2-24015", "Microsoft.TestPlatform.ObjectModel": "15.0.0-*" }, @@ -27,8 +22,26 @@ "imports": [ "dnxcore50", "portable-net45+win8" - ] - } + ], + + "dependencies": { + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.0.0" + }, + "dotnet-test-mstest": { + "version": "1.0.1-preview", + "exclude": "compile" + }, + "moq.netcore": "4.4.0-beta8" + } + }, + + "net46": { + "frameworkAssemblies": { + "System.Runtime": "" + } + } }, "testRunner": "mstest" diff --git a/test/Microsoft.TestPlatform.Utilities.UnitTests/CodeCoverageDataAdapterUtilitiesTests.cs b/test/Microsoft.TestPlatform.Utilities.UnitTests/CodeCoverageDataAdapterUtilitiesTests.cs index b0d436e684..62f64df029 100644 --- a/test/Microsoft.TestPlatform.Utilities.UnitTests/CodeCoverageDataAdapterUtilitiesTests.cs +++ b/test/Microsoft.TestPlatform.Utilities.UnitTests/CodeCoverageDataAdapterUtilitiesTests.cs @@ -1,5 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. +using System.Xml.XPath; + namespace Microsoft.TestPlatform.Utilities.Tests { using System.Xml; @@ -25,8 +27,7 @@ public void UpdateWithCodeCoverageSettingsIfNotConfiguredShouldNotUpdateIfStatic var xmlDocument = new XmlDocument(); xmlDocument.LoadXml(runSettingsXml); - CodeCoverageDataAdapterUtilities.UpdateWithCodeCoverageSettingsIfNotConfigured( - xmlDocument.ToXPathNavigable()); + CodeCoverageDataAdapterUtilities.UpdateWithCodeCoverageSettingsIfNotConfigured(GetXPathNavigable(xmlDocument)); var expectedRunSettings = ""; @@ -48,12 +49,20 @@ public void UpdateWithCodeCoverageSettingsIfNotConfiguredShouldNotUpdateIfDynami var xmlDocument = new XmlDocument(); xmlDocument.LoadXml(runSettingsXml); - CodeCoverageDataAdapterUtilities.UpdateWithCodeCoverageSettingsIfNotConfigured( - xmlDocument.ToXPathNavigable()); + CodeCoverageDataAdapterUtilities.UpdateWithCodeCoverageSettingsIfNotConfigured(GetXPathNavigable(xmlDocument)); var expectedRunSettings = ""; Assert.AreEqual(expectedRunSettings, xmlDocument.OuterXml); } + + private static IXPathNavigable GetXPathNavigable(XmlDocument doc) + { +#if NET46 + return doc; +#else + return doc.ToXPathNavigable(); +#endif + } } } diff --git a/test/Microsoft.TestPlatform.Utilities.UnitTests/MSTestSettingsUtilitiesTests.cs b/test/Microsoft.TestPlatform.Utilities.UnitTests/MSTestSettingsUtilitiesTests.cs index 48d33e243b..cf37982e0b 100644 --- a/test/Microsoft.TestPlatform.Utilities.UnitTests/MSTestSettingsUtilitiesTests.cs +++ b/test/Microsoft.TestPlatform.Utilities.UnitTests/MSTestSettingsUtilitiesTests.cs @@ -49,7 +49,7 @@ public void ImportShouldThrowIfNotLegacySettingsFile() () => MSTestSettingsUtilities.Import( "C:\\temp\\r.runsettings", - xmlDocument.ToXPathNavigable(), + GetXPathNavigable(xmlDocument), Architecture.X86, FrameworkVersion.Framework45); ExceptionUtilities.ThrowsException(action, "Unexpected settings file specified."); @@ -66,7 +66,7 @@ public void ImportShouldThrowIfDefaultRunSettingsIsIncorrect() () => MSTestSettingsUtilities.Import( "C:\\temp\\r.testsettings", - xmlDocument.ToXPathNavigable(), + GetXPathNavigable(xmlDocument), Architecture.X86, FrameworkVersion.Framework45); ExceptionUtilities.ThrowsException(action, "Could not find 'RunSettings' node."); @@ -80,7 +80,7 @@ public void ImportShouldEmbedTestSettingsInformation() xmlDocument.LoadXml(defaultRunSettingsXml); var finalxPath = MSTestSettingsUtilities.Import( "C:\\temp\\r.testsettings", - xmlDocument.ToXPathNavigable(), + GetXPathNavigable(xmlDocument), Architecture.X86, FrameworkVersion.Framework45); @@ -100,7 +100,7 @@ public void ImportShouldEmbedTestSettingsAndDefaultRunConfigurationInformation() xmlDocument.LoadXml(defaultRunSettingsXml); var finalxPath = MSTestSettingsUtilities.Import( "C:\\temp\\r.testsettings", - xmlDocument.ToXPathNavigable(), + GetXPathNavigable(xmlDocument), Architecture.X86, FrameworkVersion.Framework45); @@ -113,5 +113,14 @@ public void ImportShouldEmbedTestSettingsAndDefaultRunConfigurationInformation() } #endregion + + private static IXPathNavigable GetXPathNavigable(XmlDocument doc) + { +#if NET46 + return doc; +#else + return doc.ToXPathNavigable(); +#endif + } } } diff --git a/test/Microsoft.TestPlatform.Utilities.UnitTests/project.json b/test/Microsoft.TestPlatform.Utilities.UnitTests/project.json index f012bd59b7..7c2b297ace 100644 --- a/test/Microsoft.TestPlatform.Utilities.UnitTests/project.json +++ b/test/Microsoft.TestPlatform.Utilities.UnitTests/project.json @@ -8,15 +8,11 @@ }, "dependencies": { - "Microsoft.NETCore.App": { - "type": "platform", - "version": "1.0.0" - }, - "dotnet-test-mstest": { - "version": "1.0.1-preview", + "MSTest.TestFramework": "1.0.0-preview", + "MSTest.TestAdapter": { + "version": "1.0.3-preview", "exclude": "compile" }, - "MSTest.TestFramework": "1.0.0-preview", "Microsoft.TestPlatform.Utilities": "15.0.0-*" }, @@ -25,8 +21,25 @@ "imports": [ "dnxcore50", "portable-net45+win8" - ] - } + ], + + "dependencies": { + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.0.0" + }, + "dotnet-test-mstest": { + "version": "1.0.1-preview", + "exclude": "compile" + } + } + }, + + "net46": { + "frameworkAssemblies": { + "System.Runtime": "" + } + } }, "testRunner": "mstest" diff --git a/test/Microsoft.TestPlatform.VsTestConsole.TranslationLayer.UnitTests/project.json b/test/Microsoft.TestPlatform.VsTestConsole.TranslationLayer.UnitTests/project.json index cf5e667806..75115eb97b 100644 --- a/test/Microsoft.TestPlatform.VsTestConsole.TranslationLayer.UnitTests/project.json +++ b/test/Microsoft.TestPlatform.VsTestConsole.TranslationLayer.UnitTests/project.json @@ -8,15 +8,11 @@ }, "dependencies": { - "Microsoft.NETCore.App": { - "type": "platform", - "version": "1.0.0" - }, - "dotnet-test-mstest": { - "version": "1.0.1-preview", + "MSTest.TestFramework": "1.0.0-preview", + "MSTest.TestAdapter": { + "version": "1.0.3-preview", "exclude": "compile" }, - "MSTest.TestFramework": "1.0.0-preview", "moq.netcore": "4.4.0-beta8", "System.Diagnostics.TraceSource": "4.0.0-rc2-24015", "Microsoft.TestPlatform.VsTestConsole.TranslationLayer": "15.0.0-*", @@ -29,9 +25,26 @@ "imports": [ "dnxcore50", "portable-net45+win8" - ] - } + ], + + "dependencies": { + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.0.0" + }, + "dotnet-test-mstest": { + "version": "1.0.1-preview", + "exclude": "compile" + } + } + }, + + "net46": { + "frameworkAssemblies": { + "System.Runtime": "" + } + } }, "testRunner": "mstest" -} +} \ No newline at end of file diff --git a/test/datacollector.x86.UnitTests/DataCollectionCoordinatorTests.cs b/test/datacollector.x86.UnitTests/DataCollectionCoordinatorTests.cs index 7c7ec571ce..d3eab8da62 100644 --- a/test/datacollector.x86.UnitTests/DataCollectionCoordinatorTests.cs +++ b/test/datacollector.x86.UnitTests/DataCollectionCoordinatorTests.cs @@ -8,6 +8,7 @@ namespace Microsoft.VisualStudio.TestPlatform.DataCollector.UnitTests using System.Diagnostics; using System.Linq; using System.Threading; + using System.Threading.Tasks; using Microsoft.VisualStudio.TestPlatform.Common; using Microsoft.VisualStudio.TestPlatform.DataCollector.Interfaces; @@ -27,7 +28,7 @@ public void Initialize() { this.dummyDataCollectionManagerV1 = new DummyDataCollectionManager(); this.dummyDataCollectionManagerV2 = new DummyDataCollectionManager(); - this.dataCollectionCoordinator = new DataCollectionCoordinator(new[] { dummyDataCollectionManagerV1, dummyDataCollectionManagerV2 }); + this.dataCollectionCoordinator = new DataCollectionCoordinator(new IDataCollectionManager[] { dummyDataCollectionManagerV1, dummyDataCollectionManagerV2 }); } [TestMethod] @@ -35,15 +36,15 @@ public void BeforeTestRunStartShouldReturnBeforeTestRunStartResult() { var envVars = new Dictionary(); envVars.Add("key", "value"); - this.dummyDataCollectionManagerV1.envVariables = envVars; - this.dummyDataCollectionManagerV2.envVariables = new Dictionary(); + this.dummyDataCollectionManagerV1.EnvVariables = envVars; + this.dummyDataCollectionManagerV2.EnvVariables = new Dictionary(); var result = this.dataCollectionCoordinator.BeforeTestRunStart(settingsXml: string.Empty, resetDataCollectors: true, isRunStartingNow: true); - Assert.IsTrue(this.dummyDataCollectionManagerV1.isLoadCollectorsInvoked); - Assert.IsTrue(this.dummyDataCollectionManagerV2.isLoadCollectorsInvoked); - Assert.IsTrue(this.dummyDataCollectionManagerV1.isSessionStartedInvoked); - Assert.IsTrue(this.dummyDataCollectionManagerV2.isSessionStartedInvoked); + Assert.IsTrue(this.dummyDataCollectionManagerV1.IsLoadCollectorsInvoked); + Assert.IsTrue(this.dummyDataCollectionManagerV2.IsLoadCollectorsInvoked); + Assert.IsTrue(this.dummyDataCollectionManagerV1.IsSessionStartedInvoked); + Assert.IsTrue(this.dummyDataCollectionManagerV2.IsSessionStartedInvoked); Assert.AreEqual(1, result.EnvironmentVariables.Count); Assert.AreEqual(envVars.Keys.First(), result.EnvironmentVariables.Keys.First()); Assert.AreEqual(envVars.Values.First(), result.EnvironmentVariables.Values.First()); @@ -54,15 +55,15 @@ public void BeforeTestRunStartShouldLoadTwoDataCollectorsInParallel() { var envVars = new Dictionary(); envVars.Add("key", "value"); - this.dummyDataCollectionManagerV1.envVariables = envVars; - this.dummyDataCollectionManagerV2.envVariables = new Dictionary(); + this.dummyDataCollectionManagerV1.EnvVariables = envVars; + this.dummyDataCollectionManagerV2.EnvVariables = new Dictionary(); var result = this.dataCollectionCoordinator.BeforeTestRunStart(settingsXml: string.Empty, resetDataCollectors: true, isRunStartingNow: true); // Verify the two collectors are invoked in parallel - Assert.IsTrue(this.dummyDataCollectionManagerV1.ThreadId > 0); - Assert.IsTrue(this.dummyDataCollectionManagerV2.ThreadId > 0); - Assert.AreNotEqual(this.dummyDataCollectionManagerV1.ThreadId, this.dummyDataCollectionManagerV2.ThreadId); + Assert.IsTrue(this.dummyDataCollectionManagerV1.TaskId > 0); + Assert.IsTrue(this.dummyDataCollectionManagerV2.TaskId > 0); + Assert.AreNotEqual(this.dummyDataCollectionManagerV1.TaskId, this.dummyDataCollectionManagerV2.TaskId); } [TestMethod] @@ -78,7 +79,7 @@ public void BeforeTestRunStartShouldReturnNullIfNoDataCollectorManagersAreProvid [TestMethod] public void BeforeTestRunStartShouldThrowExceptionIfExceptionIsThrownByDataCollectionManager() { - this.dummyDataCollectionManagerV1.loadDataCollectorsThrowException = true; + this.dummyDataCollectionManagerV1.LoadDataCollectorsThrowException = true; Assert.ThrowsException( () => @@ -95,14 +96,14 @@ public void AfterTestRunEndShouldReturnAttachments() attachmentset1.Attachments.Add(new UriDataAttachment(new Uri("DataCollection://Attachment/v11"), "AttachmentV1-Attachment1")); attachments1.Add(attachmentset1); - this.dummyDataCollectionManagerV1.attachments = attachments1; - this.dummyDataCollectionManagerV2.attachments = attachments1; + this.dummyDataCollectionManagerV1.Attachments = attachments1; + this.dummyDataCollectionManagerV2.Attachments = attachments1; var result = this.dataCollectionCoordinator.AfterTestRunEnd(isCancelled: false); Assert.IsNotNull(result); - Assert.IsTrue(this.dummyDataCollectionManagerV1.isSessionEndedInvoked); - Assert.IsTrue(this.dummyDataCollectionManagerV2.isSessionEndedInvoked); + Assert.IsTrue(this.dummyDataCollectionManagerV1.IsSessionEndedInvoked); + Assert.IsTrue(this.dummyDataCollectionManagerV2.IsSessionEndedInvoked); Assert.AreEqual(2, result.Count()); } @@ -114,15 +115,15 @@ public void AfterTestRunEndShouldGetAttachmentsFromDataCollectorManagersInParall attachmentset1.Attachments.Add(new UriDataAttachment(new Uri("DataCollection://Attachment/v11"), "AttachmentV1-Attachment1")); attachments1.Add(attachmentset1); - this.dummyDataCollectionManagerV1.attachments = attachments1; - this.dummyDataCollectionManagerV2.attachments = attachments1; + this.dummyDataCollectionManagerV1.Attachments = attachments1; + this.dummyDataCollectionManagerV2.Attachments = attachments1; var result = this.dataCollectionCoordinator.AfterTestRunEnd(isCancelled: false); // Verify the two collectors are invoked in parallel - Assert.IsTrue(this.dummyDataCollectionManagerV1.ThreadId > 0); - Assert.IsTrue(this.dummyDataCollectionManagerV2.ThreadId > 0); - Assert.AreNotEqual(this.dummyDataCollectionManagerV1.ThreadId, this.dummyDataCollectionManagerV2.ThreadId); + Assert.IsTrue(this.dummyDataCollectionManagerV1.TaskId > 0); + Assert.IsTrue(this.dummyDataCollectionManagerV2.TaskId > 0); + Assert.AreNotEqual(this.dummyDataCollectionManagerV1.TaskId, this.dummyDataCollectionManagerV2.TaskId); } [TestMethod] @@ -138,7 +139,7 @@ public void AfterTestRunEndShouldReturnNullIfNoDataCollectorManagersAreProvided( [TestMethod] public void AfterTestRunEndShouldThrowExceptionIfExceptionIsThrownByDataCollectionManager() { - this.dummyDataCollectionManagerV1.sessionEndedThrowsException = true; + this.dummyDataCollectionManagerV1.SessionEndedThrowsException = true; Assert.ThrowsException( () => @@ -152,8 +153,8 @@ public void DisposeShouldCallDisposeOfDataCollectionManagers() { this.dataCollectionCoordinator.Dispose(); - Assert.IsTrue(this.dummyDataCollectionManagerV1.isDisposedInvoked); - Assert.IsTrue(this.dummyDataCollectionManagerV2.isDisposedInvoked); + Assert.IsTrue(this.dummyDataCollectionManagerV1.IsDisposedInvoked); + Assert.IsTrue(this.dummyDataCollectionManagerV2.IsDisposedInvoked); } [TestMethod] @@ -167,32 +168,32 @@ public void DisposeShouldDisposeResourcesIfNoDataCollectionManagersAreProvided() internal class DummyDataCollectionManager : IDataCollectionManager { - public bool isLoadCollectorsInvoked; - public bool isSessionStartedInvoked; - public bool isSessionEndedInvoked; - public Dictionary envVariables; - public bool loadDataCollectorsThrowException; - public Collection attachments; - public bool sessionEndedThrowsException; - public bool isDisposedInvoked; - public int ThreadId; + public bool IsLoadCollectorsInvoked; + public bool IsSessionStartedInvoked; + public bool IsSessionEndedInvoked; + public Dictionary EnvVariables; + public bool LoadDataCollectorsThrowException; + public Collection Attachments; + public bool SessionEndedThrowsException; + public bool IsDisposedInvoked; + public int TaskId; public void Dispose() { - this.isDisposedInvoked = true; + this.IsDisposedInvoked = true; } public Dictionary LoadDataCollectors(RunSettings settingsXml) { - this.ThreadId = Thread.CurrentThread.ManagedThreadId; + this.TaskId = Task.CurrentId.Value; - if (this.loadDataCollectorsThrowException) + if (this.LoadDataCollectorsThrowException) { throw new Exception("DataCollectionManagerException"); } - this.isLoadCollectorsInvoked = true; - return this.envVariables; + this.IsLoadCollectorsInvoked = true; + return this.EnvVariables; } @@ -203,21 +204,21 @@ public void TestCaseStarted(TestCaseStartEventArgs testCaseStartEventArgs) public Collection SessionEnded(bool isCancelled) { - this.ThreadId = Thread.CurrentThread.ManagedThreadId; + this.TaskId = Task.CurrentId.Value; - if (this.sessionEndedThrowsException) + if (this.SessionEndedThrowsException) { throw new Exception("DataCollectionManagerException"); } - this.isSessionEndedInvoked = true; - return this.attachments; + this.IsSessionEndedInvoked = true; + return this.Attachments; } public bool SessionStarted() { - this.ThreadId = Thread.CurrentThread.ManagedThreadId; - this.isSessionStartedInvoked = true; + this.TaskId = Task.CurrentId.Value; + this.IsSessionStartedInvoked = true; return true; } diff --git a/test/datacollector.x86.UnitTests/project.json b/test/datacollector.x86.UnitTests/project.json index f023a24637..5c0e49140d 100644 --- a/test/datacollector.x86.UnitTests/project.json +++ b/test/datacollector.x86.UnitTests/project.json @@ -8,15 +8,11 @@ }, "dependencies": { - "Microsoft.NETCore.App": { - "type": "platform", - "version": "1.0.0" - }, - "dotnet-test-mstest": { - "version": "1.0.1-preview", + "MSTest.TestFramework": "1.0.0-preview", + "MSTest.TestAdapter": { + "version": "1.0.3-preview", "exclude": "compile" }, - "MSTest.TestFramework": "1.0.0-preview", "moq.netcore": "4.4.0-beta8", "System.Diagnostics.TraceSource": "4.0.0-rc2-24015", "datacollector": "15.0.0-*" @@ -27,9 +23,26 @@ "imports": [ "dnxcore50", "portable-net45+win8" - ] - } + ], + + "dependencies": { + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.0.0" + }, + "dotnet-test-mstest": { + "version": "1.0.1-preview", + "exclude": "compile" + } + } + }, + + "net46": { + "frameworkAssemblies": { + "System.Runtime": "" + } + } }, "testRunner": "mstest" -} +} \ No newline at end of file diff --git a/test/testhost.UnitTests/project.json b/test/testhost.UnitTests/project.json index f66c69f3ad..5a85dc15a9 100644 --- a/test/testhost.UnitTests/project.json +++ b/test/testhost.UnitTests/project.json @@ -8,15 +8,11 @@ }, "dependencies": { - "Microsoft.NETCore.App": { - "type": "platform", - "version": "1.0.0" - }, - "dotnet-test-mstest": { - "version": "1.0.1-preview", + "MSTest.TestFramework": "1.0.0-preview", + "MSTest.TestAdapter": { + "version": "1.0.3-preview", "exclude": "compile" }, - "MSTest.TestFramework": "1.0.0-preview", "moq.netcore": "4.4.0-beta8", "System.Diagnostics.TraceSource": "4.0.0-rc2-24015" }, @@ -26,8 +22,25 @@ "imports": [ "dnxcore50", "portable-net45+win8" - ] - } + ], + + "dependencies": { + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.0.0" + }, + "dotnet-test-mstest": { + "version": "1.0.1-preview", + "exclude": "compile" + } + } + }, + + "net46": { + "frameworkAssemblies": { + "System.Runtime": "" + } + } }, "testRunner": "mstest" diff --git a/test/vstest.console.UnitTests/Internal/ConsoleLoggerTests.cs b/test/vstest.console.UnitTests/Internal/ConsoleLoggerTests.cs index e6e75a2bb6..865d0755ca 100644 --- a/test/vstest.console.UnitTests/Internal/ConsoleLoggerTests.cs +++ b/test/vstest.console.UnitTests/Internal/ConsoleLoggerTests.cs @@ -54,8 +54,7 @@ public void InitializeShouldThrowExceptionIfEventsIsNull() [TestMethod] public void InitializeShouldNotThrowExceptionIfEventsIsNotNull() { - var events = new Mock(); - this.consoleLogger.Initialize(events.Object, null); + this.consoleLogger.Initialize(new Mock().Object, null); } [TestMethod] @@ -71,17 +70,11 @@ public void TestMessageHandlerShouldThrowExceptionIfEventArgsIsNull() [TestMethod] public void TestMessageHandlerShouldWriteToConsoleIfTestRunEventsAreRaised() { - int count = 0; - this.mockOutput.Setup(o => o.WriteLine(It.IsAny(), It.IsAny())).Callback( - (s, o) => { count++; }); - // Raise events on mock object this.testRunRequest.Raise(m => m.TestRunMessage += null, new TestRunMessageEventArgs(TestMessageLevel.Informational, "Informational123")); this.testRunRequest.Raise(m => m.TestRunMessage += null, new TestRunMessageEventArgs(TestMessageLevel.Error, "Error123")); this.testRunRequest.Raise(m => m.TestRunMessage += null, new TestRunMessageEventArgs(TestMessageLevel.Warning, "Warning123")); - - // Added this for synchronization - SpinWait.SpinUntil(() => count == 3, 300); + this.FlushLoggerMessages(); this.mockOutput.Verify(o => o.WriteLine("Information: Informational123", OutputLevel.Information), Times.Once()); this.mockOutput.Verify(o => o.WriteLine("Warning: Warning123", OutputLevel.Warning), Times.Once()); @@ -107,6 +100,7 @@ public void TestResultHandlerShouldWriteToConsoleIfTestResultEventsAreRaised() // Raise an event on mock object this.testRunRequest.Raise(m => m.OnRunStatsChange += null, eventArgs); + this.FlushLoggerMessages(); this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, Resources.PassedTestIndicator, "TestName"), OutputLevel.Information), Times.Once()); this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, Resources.FailedTestIndicator, "TestName"), OutputLevel.Information), Times.Once()); @@ -144,7 +138,7 @@ public void TestRunCompleteHandlerShouldWriteToConsoleIfTestsPass() public void TestRunCompleteHandlerShouldWriteToConsoleIfTestsFail() { // Raise an event on mock object raised to register test case count and mark Outcome as Outcome.Failed - var eventArgs = new TestRunChangedEventArgs(null, GetTestResultObject(TestOutcome.Failed), null); + var eventArgs = new TestRunChangedEventArgs(null, this.GetTestResultObject(TestOutcome.Failed), null); this.testRunRequest.Raise(m => m.OnRunStatsChange += null, eventArgs); // Raise an event on mock object @@ -158,7 +152,7 @@ public void TestRunCompleteHandlerShouldWriteToConsoleIfTestsFail() public void PrintTimeHandlerShouldPrintElapsedTimeOnConsole() { // Raise an event on mock object raised to register test case count - var eventArgs = new TestRunChangedEventArgs(null, GetTestResultObject(TestOutcome.Passed), null); + var eventArgs = new TestRunChangedEventArgs(null, this.GetTestResultObject(TestOutcome.Passed), null); this.testRunRequest.Raise(m => m.OnRunStatsChange += null, eventArgs); // Raise events on mock object @@ -185,6 +179,7 @@ public void DisplayFullInformationShouldWriteErrorMessageAndStackTraceToConsole( // Raise an event on mock object this.testRunRequest.Raise(m => m.OnRunStatsChange += null, eventArgs); + this.FlushLoggerMessages(); this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, "{0}{1}", Resources.TestMessageFormattingPrefix, "ErrorMessage"), OutputLevel.Error), Times.Once()); this.mockOutput.Verify(o => o.Write(string.Format(CultureInfo.CurrentCulture, "{0}", "ErrorStackTrace"), OutputLevel.Error), Times.Once()); @@ -208,6 +203,7 @@ public void GetTestMessagesShouldWriteMessageAndStackTraceToConsole() // Raise an event on mock object this.testRunRequest.Raise(m => m.OnRunStatsChange += null, eventArgs); + this.FlushLoggerMessages(); // Added this for synchronization SpinWait.SpinUntil(() => count == 3, 300); @@ -226,20 +222,17 @@ public void GetTestMessagesShouldWriteMessageAndStackTraceToConsole() public void AttachmentInformationShouldBeWrittenToConsoleIfAttachmentsArePresent() { var attachmentSet = new AttachmentSet(new Uri("test://uri"), "myattachmentset"); - var uriDataAttachment = new UriDataAttachment(new Uri("file://server/filename.ext"), "description"); attachmentSet.Attachments.Add(uriDataAttachment); - var uriDataAttachment1 = new UriDataAttachment(new Uri("file://server/filename1.ext"), "description"); attachmentSet.Attachments.Add(uriDataAttachment1); - var attachmentSetList = new List(); attachmentSetList.Add(attachmentSet); - var testRunCompleteEventArgs = new TestRunCompleteEventArgs(null, false, false, null, new Collection(attachmentSetList), new TimeSpan(1, 0, 0, 0)); // Raise an event on mock object raised to register test case count and mark Outcome as Outcome.Failed this.testRunRequest.Raise(m => m.OnRunCompletion += null, testRunCompleteEventArgs); + this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, Resources.AttachmentOutputFormat, uriDataAttachment.Uri.LocalPath), OutputLevel.Information), Times.Once()); this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, Resources.AttachmentOutputFormat, uriDataAttachment1.Uri.LocalPath), OutputLevel.Information), Times.Once()); } @@ -258,9 +251,9 @@ private void Setup() this.consoleLogger.Initialize(this.events.Object, null); DummyTestLoggerManager.Cleanup(); + // Create Instance of TestLoggerManager this.testLoggerManager = TestLoggerManager.Instance; - //Console.WriteLine(TestLoggerManager.Instance.GetHashCode()); this.testLoggerManager.AddLogger(new Uri(ConsoleLogger.ExtensionUri), new Dictionary()); this.testLoggerManager.EnableLogging(); @@ -268,6 +261,14 @@ private void Setup() this.testLoggerManager.RegisterTestRunEvents(this.testRunRequest.Object); } + private void FlushLoggerMessages() + { + // Raise a test run complete message to flush out any pending messages in queue + this.testRunRequest.Raise( + m => m.OnRunCompletion += null, + new TestRunCompleteEventArgs(stats: null, isCanceled: false, isAborted: false, error: null, attachmentSets: null, elapsedTime: new TimeSpan(1, 0, 0, 0))); + } + private List GetTestResultsObject() { var testcase = new TestCase("TestName", new Uri("some://uri"), "TestSource"); @@ -300,4 +301,4 @@ private void Setup() return testresultList; } } -} +} \ No newline at end of file diff --git a/test/vstest.console.UnitTests/project.json b/test/vstest.console.UnitTests/project.json index 9a5054f7ac..756e6ed959 100644 --- a/test/vstest.console.UnitTests/project.json +++ b/test/vstest.console.UnitTests/project.json @@ -8,15 +8,11 @@ }, "dependencies": { - "Microsoft.NETCore.App": { - "type": "platform", - "version": "1.0.0" - }, - "dotnet-test-mstest": { - "version": "1.0.1-preview", + "MSTest.TestFramework": "1.0.0-preview", + "MSTest.TestAdapter": { + "version": "1.0.3-preview", "exclude": "compile" }, - "MSTest.TestFramework": "1.0.0-preview", "moq.netcore": "4.4.0-beta8", "System.Diagnostics.TraceSource": "4.0.0-rc2-24015", "vstest.console": "15.0.0-*", @@ -28,9 +24,26 @@ "imports": [ "dnxcore50", "portable-net45+win8" - ] - } + ], + + "dependencies": { + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.0.0" + }, + "dotnet-test-mstest": { + "version": "1.0.1-preview", + "exclude": "compile" + } + } + }, + + "net46": { + "frameworkAssemblies": { + "System.Runtime": "" + } + } }, "testRunner": "mstest" -} +} \ No newline at end of file