Merge pull request #6151 from smadala/rd-arg

Add results-directory switch to dotnet test
This commit is contained in:
Livar 2017-04-04 08:31:58 -07:00 committed by GitHub
commit 6c5d622b9e
3 changed files with 43 additions and 51 deletions

View file

@ -60,5 +60,10 @@ namespace Microsoft.DotNet.Tools.Test
public const string RunSettingsArgsHelpText = @"Any extra command-line runsettings arguments that should be passed to vstest. See 'dotnet vstest --help' for available options.
Example: -- RunConfiguration.ResultsDirectory=""C:\users\user\desktop\Results Directory"" MSTest.DeploymentEnabled=false";
public const string CmdResultsDirectoryDescription = @"The directory where the test results are going to be placed. The specified directory will be created if it does not exist.
Example: --results-directory <PATH_TO_RESULTS_DIRECTORY>";
public const string CmdPathToResultsDirectory = "PATH_TO_RESULTS_DIRECTORY";
}
}

View file

@ -68,6 +68,12 @@ namespace Microsoft.DotNet.Cli
LocalizableStrings.CmdNoBuildDescription,
Accept.NoArguments()
.ForwardAsSingle(o => "/p:VSTestNoBuild=true")),
Create.Option(
"-r|--results-directory",
LocalizableStrings.CmdResultsDirectoryDescription,
Accept.ExactlyOneArgument()
.With(name: LocalizableStrings.CmdPathToResultsDirectory)
.ForwardAsSingle(o => $"/p:VSTestResultsDirectory={o.Arguments.Single()}")),
CommonOptions.VerbosityOption());
private static string GetSemiColonEsacpedstring(string arg)

View file

@ -76,21 +76,8 @@ namespace Microsoft.DotNet.Cli.Test.Tests
[Fact]
public void TestWillNotBuildTheProjectIfNoBuildArgsIsGiven()
{
// Copy VSTestDotNetCore project in output directory of project dotnet-vstest.Tests
string testAppName = "VSTestDotNetCore";
var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles();
var testProjectDirectory = testInstance.Root.FullName;
// Restore project VSTestDotNetCore
new RestoreCommand()
.WithWorkingDirectory(testProjectDirectory)
.Execute()
.Should()
.Pass();
// Copy and restore VSTestDotNetCore project in output directory of project dotnet-vstest.Tests
var testProjectDirectory = this.CopyAndRestoreVSTestDotNetCoreTestApp();
string configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
string expectedError = Path.Combine(testProjectDirectory, "bin",
configuration, "netcoreapp2.0", "VSTestDotNetCore.dll");
@ -106,24 +93,12 @@ namespace Microsoft.DotNet.Cli.Test.Tests
}
[Fact]
public void TestWillCreateTrxLogger()
public void TestWillCreateTrxLoggerInTheSpecifiedResultsDirectoryBySwitch()
{
// Copy VSTestDotNetCore project in output directory of project dotnet-vstest.Tests
string testAppName = "VSTestDotNetCore";
var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles();
// Copy and restore VSTestDotNetCore project in output directory of project dotnet-vstest.Tests
var testProjectDirectory = this.CopyAndRestoreVSTestDotNetCoreTestApp();
var testProjectDirectory = testInstance.Root.FullName;
// Restore project VSTestDotNetCore
new RestoreCommand()
.WithWorkingDirectory(testProjectDirectory)
.Execute()
.Should()
.Pass();
string trxLoggerDirectory = Path.Combine(testProjectDirectory, "TestResults");
string trxLoggerDirectory = Path.Combine(testProjectDirectory, "TestResults", "netcoreappx.y");
// Delete trxLoggerDirectory if it exist
if (Directory.Exists(trxLoggerDirectory))
@ -131,10 +106,10 @@ namespace Microsoft.DotNet.Cli.Test.Tests
Directory.Delete(trxLoggerDirectory, true);
}
// Call test with logger enable
// Call test with trx logger enabled and results directory explicitly specified.
CommandResult result = new DotnetTestCommand()
.WithWorkingDirectory(testProjectDirectory)
.ExecuteWithCapturedOutput("--logger trx");
.ExecuteWithCapturedOutput("--logger trx -r \"" + trxLoggerDirectory + "\"");
// Verify
String[] trxFiles = Directory.GetFiles(trxLoggerDirectory, "*.trx");
@ -149,22 +124,10 @@ namespace Microsoft.DotNet.Cli.Test.Tests
}
[Fact]
public void ItCreatesTrxReportInTheSpecifiedResultsDirectory()
public void ItCreatesTrxReportInTheSpecifiedResultsDirectoryByArgs()
{
// Copy VSTestDotNetCore project in output directory of project dotnet-vstest.Tests
string testAppName = "VSTestDotNetCore";
var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles();
var testProjectDirectory = testInstance.Root.FullName;
// Restore project VSTestDotNetCore
new RestoreCommand()
.WithWorkingDirectory(testProjectDirectory)
.Execute()
.Should()
.Pass();
// Copy and restore VSTestDotNetCore project in output directory of project dotnet-vstest.Tests
var testProjectDirectory = this.CopyAndRestoreVSTestDotNetCoreTestApp();
string trxLoggerDirectory = Path.Combine(testProjectDirectory, "ResultsDirectory");
@ -180,9 +143,9 @@ namespace Microsoft.DotNet.Cli.Test.Tests
.ExecuteWithCapturedOutput("--logger \"trx;logfilename=custom.trx\" -- RunConfiguration.ResultsDirectory=" + trxLoggerDirectory);
// Verify
String[] trxFiles = Directory.GetFiles(trxLoggerDirectory, "custom.trx");
Assert.Equal(1, trxFiles.Length);
result.StdOut.Should().Contain(trxFiles[0]);
var trxFilePath = Path.Combine(trxLoggerDirectory, "custom.trx");
Assert.True(File.Exists(trxFilePath));
result.StdOut.Should().Contain(trxFilePath);
// Cleanup trxLoggerDirectory if it exist
if (Directory.Exists(trxLoggerDirectory))
@ -221,5 +184,23 @@ namespace Microsoft.DotNet.Cli.Test.Tests
result.StdOut.Should().Contain("Passed TestNamespace.VSTestTests.VSTestPassTest");
result.StdOut.Should().Contain("Failed TestNamespace.VSTestTests.VSTestFailTest");
}
private string CopyAndRestoreVSTestDotNetCoreTestApp(){
// Copy VSTestDotNetCore project in output directory of project dotnet-vstest.Tests
string testAppName = "VSTestDotNetCore";
var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles();
var testProjectDirectory = testInstance.Root.FullName;
// Restore project VSTestDotNetCore
new RestoreCommand()
.WithWorkingDirectory(testProjectDirectory)
.Execute()
.Should()
.Pass();
return testProjectDirectory;
}
}
}