Add results directory arg to dotnet test
This commit is contained in:
parent
61bffa5030
commit
8a6913b2fe
3 changed files with 47 additions and 54 deletions
|
@ -58,5 +58,7 @@ 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 test results directory will be created in the specified path if it does not exist.
|
||||
Example: --results-directory <PATH_TO_RESULTS_DIRECTORY>";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,9 +79,14 @@ namespace Microsoft.DotNet.Tools.Test
|
|||
CommandOptionType.SingleValue);
|
||||
|
||||
var noBuildtOption = cmd.Option(
|
||||
"--no-build",
|
||||
LocalizableStrings.CmdNoBuildDescription,
|
||||
CommandOptionType.NoValue);
|
||||
"--no-build",
|
||||
LocalizableStrings.CmdNoBuildDescription,
|
||||
CommandOptionType.NoValue);
|
||||
|
||||
var resultsDirectoryOption = cmd.Option(
|
||||
"-r|--results-directory",
|
||||
LocalizableStrings.CmdResultsDirectoryDescription,
|
||||
CommandOptionType.SingleValue);
|
||||
|
||||
CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(cmd);
|
||||
|
||||
|
@ -144,6 +149,11 @@ namespace Microsoft.DotNet.Tools.Test
|
|||
msbuildArgs.Add($"/p:VSTestNoBuild=true");
|
||||
}
|
||||
|
||||
if (resultsDirectoryOption.HasValue())
|
||||
{
|
||||
msbuildArgs.Add($"/p:VSTestResultsDirectory={resultsDirectoryOption.Value()}");
|
||||
}
|
||||
|
||||
if (verbosityOption.HasValue())
|
||||
{
|
||||
msbuildArgs.Add($"/verbosity:{verbosityOption.Value()}");
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue