diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Hosting/DotnetTestHostManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Hosting/DotnetTestHostManager.cs index 4848d3110c..40cdb8d058 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Hosting/DotnetTestHostManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Hosting/DotnetTestHostManager.cs @@ -177,7 +177,7 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo( // G:\tmp\netcore-test\bin\Debug\netcoreapp1.0\netcore-test.dll startInfo.Arguments = args; startInfo.EnvironmentVariables = environmentVariables ?? new Dictionary(); - startInfo.WorkingDirectory = Directory.GetCurrentDirectory(); + startInfo.WorkingDirectory = sourceDirectory; return startInfo; } diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/ExecutionTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/ExecutionTests.cs index 2bef45604e..e58cc68761 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/ExecutionTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/ExecutionTests.cs @@ -72,5 +72,20 @@ public void RunMultipleTestAssembliesInParallel(string runnerFramework, string t $"Number of {testhostProcessName} process created, expected: {expectedNumOfProcessCreated} actual: {numOfProcessCreatedTask.Result}"); this.ValidateSummaryStatus(2, 2, 2); } + + [CustomDataTestMethod] + [NET46TargetFramework] + [NETCORETargetFramework] + public void WorkingDirectoryIsSourceDirectory(string runnerFramework, string targetFramework, string targetRuntime) + { + AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerFramework, targetFramework, targetRuntime); + + var assemblyPaths = + this.BuildMultipleAssemblyPath("SimpleTestProject3.dll").Trim('\"'); + var arguments = PrepareArguments(assemblyPaths, this.GetTestAdapterPath(), string.Empty, this.FrameworkArgValue); + arguments = string.Concat(arguments, " /tests:WorkingDirectoryTest"); + this.InvokeVsTest(arguments); + this.ValidateSummaryStatus(1, 0, 0); + } } } \ No newline at end of file diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Hosting/DotnetTestHostManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Hosting/DotnetTestHostManagerTests.cs index 6e9c7e9c7a..da34657b15 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Hosting/DotnetTestHostManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Hosting/DotnetTestHostManagerTests.cs @@ -257,14 +257,14 @@ public void GetTestHostProcessStartInfoShouldThrowExceptionWhenDotnetIsNotInstal } [TestMethod] - public void GetTestHostProcessStartInfoShouldIncludeCurrentDirectoryAsWorkingDirectory() + public void GetTestHostProcessStartInfoShouldIncludeSourceDirectoryAsWorkingDirectory() { // Absolute path to the source directory var sourcePath = Path.Combine($"{Path.DirectorySeparatorChar}tmp", "test.dll"); this.mockFileHelper.Setup(ph => ph.Exists(@"\tmp\testhost.dll")).Returns(true); var startInfo = this.dotnetHostManager.GetTestHostProcessStartInfo(new[] { sourcePath }, null, this.defaultConnectionInfo); - Assert.AreEqual(Directory.GetCurrentDirectory(), startInfo.WorkingDirectory); + Assert.AreEqual($"{Path.DirectorySeparatorChar}tmp", startInfo.WorkingDirectory); } [TestMethod] diff --git a/test/TestAssets/SimpleTestProject3/SimpleTestProject3.csproj b/test/TestAssets/SimpleTestProject3/SimpleTestProject3.csproj index ef036a0ef0..f744b66f64 100644 --- a/test/TestAssets/SimpleTestProject3/SimpleTestProject3.csproj +++ b/test/TestAssets/SimpleTestProject3/SimpleTestProject3.csproj @@ -2,8 +2,6 @@ netcoreapp1.0;net46;netcoreapp1.1 SimpleTestProject3 - $(PackageTargetFallback);dnxcore50;portable-net45+win8 - Exe @@ -41,13 +39,7 @@ - - portable - - - full - $(DefineConstants);RELEASE - \ No newline at end of file + diff --git a/test/TestAssets/SimpleTestProject3/UnitTest1.cs b/test/TestAssets/SimpleTestProject3/UnitTest1.cs index 5f9361306b..b16d5bf7e8 100644 --- a/test/TestAssets/SimpleTestProject3/UnitTest1.cs +++ b/test/TestAssets/SimpleTestProject3/UnitTest1.cs @@ -5,31 +5,16 @@ namespace SampleUnitTestProject3 { using Microsoft.VisualStudio.TestTools.UnitTesting; + using System.IO; + using System.Reflection; [TestClass] public class UnitTest1 { [TestMethod] - public void PassingTest() - { - Assert.AreEqual(2, 2); - } - - [TestMethod] - public async Task AsyncTestMethod() - { - await Task.CompletedTask; - } - } - - public class Class1 - { - public void OverLoadededMethod() - { - } - - public void OverLoadededMethod(string name) + public void WorkingDirectoryTest() { + Assert.AreEqual(Path.GetDirectoryName(typeof(UnitTest1).GetTypeInfo().Assembly.Location), Directory.GetCurrentDirectory()); } } }