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.
|
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";
|
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);
|
CommandOptionType.SingleValue);
|
||||||
|
|
||||||
var noBuildtOption = cmd.Option(
|
var noBuildtOption = cmd.Option(
|
||||||
"--no-build",
|
"--no-build",
|
||||||
LocalizableStrings.CmdNoBuildDescription,
|
LocalizableStrings.CmdNoBuildDescription,
|
||||||
CommandOptionType.NoValue);
|
CommandOptionType.NoValue);
|
||||||
|
|
||||||
|
var resultsDirectoryOption = cmd.Option(
|
||||||
|
"-r|--results-directory",
|
||||||
|
LocalizableStrings.CmdResultsDirectoryDescription,
|
||||||
|
CommandOptionType.SingleValue);
|
||||||
|
|
||||||
CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(cmd);
|
CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(cmd);
|
||||||
|
|
||||||
|
@ -144,6 +149,11 @@ namespace Microsoft.DotNet.Tools.Test
|
||||||
msbuildArgs.Add($"/p:VSTestNoBuild=true");
|
msbuildArgs.Add($"/p:VSTestNoBuild=true");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (resultsDirectoryOption.HasValue())
|
||||||
|
{
|
||||||
|
msbuildArgs.Add($"/p:VSTestResultsDirectory={resultsDirectoryOption.Value()}");
|
||||||
|
}
|
||||||
|
|
||||||
if (verbosityOption.HasValue())
|
if (verbosityOption.HasValue())
|
||||||
{
|
{
|
||||||
msbuildArgs.Add($"/verbosity:{verbosityOption.Value()}");
|
msbuildArgs.Add($"/verbosity:{verbosityOption.Value()}");
|
||||||
|
|
|
@ -76,21 +76,8 @@ namespace Microsoft.DotNet.Cli.Test.Tests
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TestWillNotBuildTheProjectIfNoBuildArgsIsGiven()
|
public void TestWillNotBuildTheProjectIfNoBuildArgsIsGiven()
|
||||||
{
|
{
|
||||||
// Copy VSTestDotNetCore project in output directory of project dotnet-vstest.Tests
|
// Copy and restore VSTestDotNetCore project in output directory of project dotnet-vstest.Tests
|
||||||
string testAppName = "VSTestDotNetCore";
|
var testProjectDirectory = this.CopyAndRestoreVSTestDotNetCoreTestApp();
|
||||||
var testInstance = TestAssets.Get(testAppName)
|
|
||||||
.CreateInstance()
|
|
||||||
.WithSourceFiles();
|
|
||||||
|
|
||||||
var testProjectDirectory = testInstance.Root.FullName;
|
|
||||||
|
|
||||||
// Restore project VSTestDotNetCore
|
|
||||||
new RestoreCommand()
|
|
||||||
.WithWorkingDirectory(testProjectDirectory)
|
|
||||||
.Execute()
|
|
||||||
.Should()
|
|
||||||
.Pass();
|
|
||||||
|
|
||||||
string configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
|
string configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
|
||||||
string expectedError = Path.Combine(testProjectDirectory, "bin",
|
string expectedError = Path.Combine(testProjectDirectory, "bin",
|
||||||
configuration, "netcoreapp2.0", "VSTestDotNetCore.dll");
|
configuration, "netcoreapp2.0", "VSTestDotNetCore.dll");
|
||||||
|
@ -106,24 +93,12 @@ namespace Microsoft.DotNet.Cli.Test.Tests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TestWillCreateTrxLogger()
|
public void TestWillCreateTrxLoggerInTheSpecifiedResultsDirectoryBySwitch()
|
||||||
{
|
{
|
||||||
// Copy VSTestDotNetCore project in output directory of project dotnet-vstest.Tests
|
// Copy and restore VSTestDotNetCore project in output directory of project dotnet-vstest.Tests
|
||||||
string testAppName = "VSTestDotNetCore";
|
var testProjectDirectory = this.CopyAndRestoreVSTestDotNetCoreTestApp();
|
||||||
var testInstance = TestAssets.Get(testAppName)
|
|
||||||
.CreateInstance()
|
|
||||||
.WithSourceFiles();
|
|
||||||
|
|
||||||
var testProjectDirectory = testInstance.Root.FullName;
|
string trxLoggerDirectory = Path.Combine(testProjectDirectory, "TestResults", "netcoreappx.y");
|
||||||
|
|
||||||
// Restore project VSTestDotNetCore
|
|
||||||
new RestoreCommand()
|
|
||||||
.WithWorkingDirectory(testProjectDirectory)
|
|
||||||
.Execute()
|
|
||||||
.Should()
|
|
||||||
.Pass();
|
|
||||||
|
|
||||||
string trxLoggerDirectory = Path.Combine(testProjectDirectory, "TestResults");
|
|
||||||
|
|
||||||
// Delete trxLoggerDirectory if it exist
|
// Delete trxLoggerDirectory if it exist
|
||||||
if (Directory.Exists(trxLoggerDirectory))
|
if (Directory.Exists(trxLoggerDirectory))
|
||||||
|
@ -131,10 +106,10 @@ namespace Microsoft.DotNet.Cli.Test.Tests
|
||||||
Directory.Delete(trxLoggerDirectory, true);
|
Directory.Delete(trxLoggerDirectory, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call test with logger enable
|
// Call test with trx logger enabled and results directory explicitly specified.
|
||||||
CommandResult result = new DotnetTestCommand()
|
CommandResult result = new DotnetTestCommand()
|
||||||
.WithWorkingDirectory(testProjectDirectory)
|
.WithWorkingDirectory(testProjectDirectory)
|
||||||
.ExecuteWithCapturedOutput("--logger:trx");
|
.ExecuteWithCapturedOutput("--logger:trx -r \"" + trxLoggerDirectory + "\"");
|
||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
String[] trxFiles = Directory.GetFiles(trxLoggerDirectory, "*.trx");
|
String[] trxFiles = Directory.GetFiles(trxLoggerDirectory, "*.trx");
|
||||||
|
@ -149,22 +124,10 @@ namespace Microsoft.DotNet.Cli.Test.Tests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ItCreatesTrxReportInTheSpecifiedResultsDirectory()
|
public void ItCreatesTrxReportInTheSpecifiedResultsDirectoryByArgs()
|
||||||
{
|
{
|
||||||
// Copy VSTestDotNetCore project in output directory of project dotnet-vstest.Tests
|
// Copy and restore VSTestDotNetCore project in output directory of project dotnet-vstest.Tests
|
||||||
string testAppName = "VSTestDotNetCore";
|
var testProjectDirectory = this.CopyAndRestoreVSTestDotNetCoreTestApp();
|
||||||
var testInstance = TestAssets.Get(testAppName)
|
|
||||||
.CreateInstance()
|
|
||||||
.WithSourceFiles();
|
|
||||||
|
|
||||||
var testProjectDirectory = testInstance.Root.FullName;
|
|
||||||
|
|
||||||
// Restore project VSTestDotNetCore
|
|
||||||
new RestoreCommand()
|
|
||||||
.WithWorkingDirectory(testProjectDirectory)
|
|
||||||
.Execute()
|
|
||||||
.Should()
|
|
||||||
.Pass();
|
|
||||||
|
|
||||||
string trxLoggerDirectory = Path.Combine(testProjectDirectory, "ResultsDirectory");
|
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);
|
.ExecuteWithCapturedOutput("--logger \"trx;logfilename=custom.trx\" -- RunConfiguration.ResultsDirectory=" + trxLoggerDirectory);
|
||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
String[] trxFiles = Directory.GetFiles(trxLoggerDirectory, "custom.trx");
|
var trxFilePath = Path.Combine(trxLoggerDirectory, "custom.trx");
|
||||||
Assert.Equal(1, trxFiles.Length);
|
Assert.True(File.Exists(trxFilePath));
|
||||||
result.StdOut.Should().Contain(trxFiles[0]);
|
result.StdOut.Should().Contain(trxFilePath);
|
||||||
|
|
||||||
// Cleanup trxLoggerDirectory if it exist
|
// Cleanup trxLoggerDirectory if it exist
|
||||||
if (Directory.Exists(trxLoggerDirectory))
|
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("Passed TestNamespace.VSTestTests.VSTestPassTest");
|
||||||
result.StdOut.Should().Contain("Failed TestNamespace.VSTestTests.VSTestFailTest");
|
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…
Add table
Add a link
Reference in a new issue