Skip to content

Commit

Permalink
Add results directory arg to VSTestTask (microsoft#337)
Browse files Browse the repository at this point in the history
* Add results directory arg to VSTestTask

* Nit fixes
  • Loading branch information
smadala authored and codito committed Jan 17, 2017
1 parent ffce17e commit cc1f3f5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Copyright (c) .NET Foundation. All rights reserved.
VSTestDiag="$(VSTestDiag)"
VSTestCLIRunSettings="$(VSTestCLIRunSettings)"
VSTestConsolePath="$(VSTestConsoleFile)"
VSTestResultsDirectory="$(VSTestResultsDirectory)"
/>
</Target>

Expand Down Expand Up @@ -76,6 +77,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<Message Text="VSTestListTests = $(VSTestListTests)" Importance="low" />
<Message Text="VSTestDiag = $(VSTestDiag)" Importance="low" />
<Message Text="VSTestCLIRunSettings = $(VSTestCLIRunSettings)" Importance="low" />
<Message Text="VSTestResultsDirectory = $(VSTestResultsDirectory)" Importance="low" />
</Target>

</Project>
11 changes: 11 additions & 0 deletions src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ public string VSTestConsolePath
set;
}

public string VSTestResultsDirectory
{
get;
set;
}

public override bool Execute()
{
var traceEnabledValue = Environment.GetEnvironmentVariable("VSTEST_BUILD_TRACE");
Expand Down Expand Up @@ -142,6 +148,11 @@ internal IEnumerable<string> CreateArgument()
allArgs.Add("--logger:" + this.VSTestLogger);
}

if (!string.IsNullOrEmpty(this.VSTestResultsDirectory))
{
allArgs.Add("--resultsDirectory:" + this.AddDoubleQuotes(this.VSTestResultsDirectory));
}

if (!string.IsNullOrEmpty(this.VSTestListTests))
{
allArgs.Add("--listTests");
Expand Down
15 changes: 15 additions & 0 deletions test/Microsoft.TestPlatform.Build.UnitTests/VsTestTaskTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,20 @@ public void CreateArgumentShouldAddDoubleQuotesForCLIRunSettings()
Assert.AreEqual($"\"{arg1}\"", result[3]);
Assert.AreEqual($"\"{arg2}\"", result[4]);
}

[TestMethod]
public void CreateArgumentShouldPassResultsDirectoryCorrectly()
{
const string resultsDirectoryValue = @"C:\tmp\ResultsDirectory";
var vstestTask = new VSTestTask { VSTestResultsDirectory = resultsDirectoryValue };

// Add values for required properties.
vstestTask.TestFileFullPath = "abc";
vstestTask.VSTestFramework = "abc";

var result = vstestTask.CreateArgument().ToArray();

Assert.AreEqual($"--resultsDirectory:\"{resultsDirectoryValue}\"", result[1]);
}
}
}

0 comments on commit cc1f3f5

Please sign in to comment.