2016-10-04 15:37:36 +05:30
|
|
|
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
|
|
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
|
|
|
|
using Xunit;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using Microsoft.DotNet.TestFramework;
|
|
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
2016-10-25 20:10:18 +05:30
|
|
|
|
using System.IO;
|
2016-10-25 20:57:59 +05:30
|
|
|
|
using System;
|
2016-10-04 15:37:36 +05:30
|
|
|
|
|
2016-10-28 20:15:38 +05:30
|
|
|
|
namespace Microsoft.DotNet.Cli.Test.Tests
|
2016-10-04 15:37:36 +05:30
|
|
|
|
{
|
2016-10-27 18:46:43 -07:00
|
|
|
|
public class GivenDotnettestBuildsAndRunsTestfromCsproj : TestBase
|
2016-10-04 15:37:36 +05:30
|
|
|
|
{
|
2016-11-02 03:01:13 +05:30
|
|
|
|
[Fact]
|
2016-11-02 23:38:20 +05:30
|
|
|
|
public void MSTestSingleTFM()
|
2016-10-04 15:37:36 +05:30
|
|
|
|
{
|
2016-11-03 00:14:03 +05:30
|
|
|
|
// Copy VSTestDotNetCore project in output directory of project dotnet-vstest.Tests
|
|
|
|
|
string testAppName = "VSTestDotNetCore";
|
2017-02-15 15:35:03 -08:00
|
|
|
|
var testInstance = TestAssets.Get(testAppName)
|
|
|
|
|
.CreateInstance()
|
|
|
|
|
.WithSourceFiles();
|
2016-10-04 15:37:36 +05:30
|
|
|
|
|
2017-02-15 15:35:03 -08:00
|
|
|
|
var testProjectDirectory = testInstance.Root.FullName;
|
2016-10-04 15:37:36 +05:30
|
|
|
|
|
2016-11-03 00:14:03 +05:30
|
|
|
|
// Restore project VSTestDotNetCore
|
2016-10-27 18:46:43 -07:00
|
|
|
|
new RestoreCommand()
|
2016-10-04 15:37:36 +05:30
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should()
|
|
|
|
|
.Pass();
|
|
|
|
|
|
2016-10-27 18:46:43 -07:00
|
|
|
|
// Call test
|
|
|
|
|
CommandResult result = new DotnetTestCommand()
|
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
2017-02-18 23:05:33 +05:30
|
|
|
|
.ExecuteWithCapturedOutput(TestBase.ConsoleLoggerOutputNormal);
|
2016-10-04 15:37:36 +05:30
|
|
|
|
|
|
|
|
|
// Verify
|
|
|
|
|
result.StdOut.Should().Contain("Total tests: 2. Passed: 1. Failed: 1. Skipped: 0.");
|
|
|
|
|
result.StdOut.Should().Contain("Passed TestNamespace.VSTestTests.VSTestPassTest");
|
|
|
|
|
result.StdOut.Should().Contain("Failed TestNamespace.VSTestTests.VSTestFailTest");
|
2016-12-16 15:39:52 +05:30
|
|
|
|
result.ExitCode.Should().Be(1);
|
2016-10-04 15:37:36 +05:30
|
|
|
|
}
|
2016-10-25 20:10:18 +05:30
|
|
|
|
|
2016-11-02 03:01:13 +05:30
|
|
|
|
[Fact]
|
2016-11-02 23:38:20 +05:30
|
|
|
|
public void XunitSingleTFM()
|
2016-11-02 01:45:44 +05:30
|
|
|
|
{
|
2016-11-03 00:14:03 +05:30
|
|
|
|
// Copy VSTestXunitDotNetCore project in output directory of project dotnet-vstest.Tests
|
|
|
|
|
string testAppName = "VSTestXunitDotNetCore";
|
2017-02-15 15:35:03 -08:00
|
|
|
|
var testInstance = TestAssets.Get(testAppName)
|
|
|
|
|
.CreateInstance()
|
|
|
|
|
.WithSourceFiles();
|
2016-11-02 01:45:44 +05:30
|
|
|
|
|
2017-02-15 15:35:03 -08:00
|
|
|
|
var testProjectDirectory = testInstance.Root.FullName;
|
2016-11-02 01:45:44 +05:30
|
|
|
|
|
2016-11-03 00:14:03 +05:30
|
|
|
|
// Restore project VSTestXunitDotNetCore
|
2016-11-02 01:45:44 +05:30
|
|
|
|
new RestoreCommand()
|
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should()
|
|
|
|
|
.Pass();
|
|
|
|
|
|
|
|
|
|
// Call test
|
|
|
|
|
CommandResult result = new DotnetTestCommand()
|
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
2017-02-18 23:05:33 +05:30
|
|
|
|
.ExecuteWithCapturedOutput(TestBase.ConsoleLoggerOutputNormal);
|
2016-11-02 01:45:44 +05:30
|
|
|
|
|
|
|
|
|
// Verify
|
|
|
|
|
result.StdOut.Should().Contain("Total tests: 2. Passed: 1. Failed: 1. Skipped: 0.");
|
|
|
|
|
result.StdOut.Should().Contain("Passed TestNamespace.VSTestXunitTests.VSTestXunitPassTest");
|
|
|
|
|
result.StdOut.Should().Contain("Failed TestNamespace.VSTestXunitTests.VSTestXunitFailTest");
|
2016-12-16 15:39:52 +05:30
|
|
|
|
result.ExitCode.Should().Be(1);
|
2016-11-02 01:45:44 +05:30
|
|
|
|
}
|
|
|
|
|
|
2016-11-02 03:01:13 +05:30
|
|
|
|
[Fact]
|
2016-10-25 20:10:18 +05:30
|
|
|
|
public void TestWillNotBuildTheProjectIfNoBuildArgsIsGiven()
|
|
|
|
|
{
|
2017-03-25 15:18:14 +05:30
|
|
|
|
// Copy and restore VSTestDotNetCore project in output directory of project dotnet-vstest.Tests
|
|
|
|
|
var testProjectDirectory = this.CopyAndRestoreVSTestDotNetCoreTestApp();
|
2016-10-25 20:57:59 +05:30
|
|
|
|
string configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
|
2016-10-26 16:53:34 +05:30
|
|
|
|
string expectedError = Path.Combine(testProjectDirectory, "bin",
|
2017-03-02 21:43:06 -08:00
|
|
|
|
configuration, "netcoreapp2.0", "VSTestDotNetCore.dll");
|
2016-10-26 16:53:34 +05:30
|
|
|
|
expectedError = "The test source file " + "\"" + expectedError + "\"" + " provided was not found.";
|
2016-10-25 20:10:18 +05:30
|
|
|
|
|
2016-11-01 22:01:30 +05:30
|
|
|
|
// Call test
|
2016-10-28 20:15:38 +05:30
|
|
|
|
CommandResult result = new DotnetTestCommand()
|
2016-10-26 16:53:34 +05:30
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
2016-12-12 23:29:29 -08:00
|
|
|
|
.ExecuteWithCapturedOutput("--no-build");
|
2016-10-25 20:10:18 +05:30
|
|
|
|
|
|
|
|
|
// Verify
|
2016-10-26 16:53:34 +05:30
|
|
|
|
result.StdOut.Should().Contain(expectedError);
|
2016-10-25 20:10:18 +05:30
|
|
|
|
}
|
2016-11-24 14:18:54 +05:30
|
|
|
|
|
|
|
|
|
[Fact]
|
2017-03-25 15:18:14 +05:30
|
|
|
|
public void TestWillCreateTrxLoggerInTheSpecifiedResultsDirectoryBySwitch()
|
2016-12-30 15:47:15 +05:30
|
|
|
|
{
|
2017-03-25 15:18:14 +05:30
|
|
|
|
// Copy and restore VSTestDotNetCore project in output directory of project dotnet-vstest.Tests
|
|
|
|
|
var testProjectDirectory = this.CopyAndRestoreVSTestDotNetCoreTestApp();
|
2016-11-24 14:18:54 +05:30
|
|
|
|
|
2017-03-25 15:18:14 +05:30
|
|
|
|
string trxLoggerDirectory = Path.Combine(testProjectDirectory, "TestResults", "netcoreappx.y");
|
2016-11-24 14:18:54 +05:30
|
|
|
|
|
|
|
|
|
// Delete trxLoggerDirectory if it exist
|
2017-02-15 15:35:03 -08:00
|
|
|
|
if (Directory.Exists(trxLoggerDirectory))
|
2016-11-24 14:18:54 +05:30
|
|
|
|
{
|
|
|
|
|
Directory.Delete(trxLoggerDirectory, true);
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-25 15:18:14 +05:30
|
|
|
|
// Call test with trx logger enabled and results directory explicitly specified.
|
2016-11-24 14:18:54 +05:30
|
|
|
|
CommandResult result = new DotnetTestCommand()
|
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
2017-03-25 16:33:01 +05:30
|
|
|
|
.ExecuteWithCapturedOutput("--logger trx -r \"" + trxLoggerDirectory + "\"");
|
2016-11-24 14:18:54 +05:30
|
|
|
|
|
|
|
|
|
// Verify
|
|
|
|
|
String[] trxFiles = Directory.GetFiles(trxLoggerDirectory, "*.trx");
|
|
|
|
|
Assert.Equal(1, trxFiles.Length);
|
|
|
|
|
result.StdOut.Should().Contain(trxFiles[0]);
|
2016-11-28 09:45:17 +01:00
|
|
|
|
|
|
|
|
|
// Cleanup trxLoggerDirectory if it exist
|
|
|
|
|
if(Directory.Exists(trxLoggerDirectory))
|
|
|
|
|
{
|
|
|
|
|
Directory.Delete(trxLoggerDirectory, true);
|
|
|
|
|
}
|
2016-11-24 14:18:54 +05:30
|
|
|
|
}
|
2016-12-18 00:45:25 -08:00
|
|
|
|
|
2016-12-30 11:24:03 +05:30
|
|
|
|
[Fact]
|
2017-03-25 15:18:14 +05:30
|
|
|
|
public void ItCreatesTrxReportInTheSpecifiedResultsDirectoryByArgs()
|
2016-12-30 11:24:03 +05:30
|
|
|
|
{
|
2017-03-25 15:18:14 +05:30
|
|
|
|
// Copy and restore VSTestDotNetCore project in output directory of project dotnet-vstest.Tests
|
|
|
|
|
var testProjectDirectory = this.CopyAndRestoreVSTestDotNetCoreTestApp();
|
2016-12-30 11:24:03 +05:30
|
|
|
|
|
|
|
|
|
string trxLoggerDirectory = Path.Combine(testProjectDirectory, "ResultsDirectory");
|
|
|
|
|
|
|
|
|
|
// Delete trxLoggerDirectory if it exist
|
|
|
|
|
if (Directory.Exists(trxLoggerDirectory))
|
|
|
|
|
{
|
|
|
|
|
Directory.Delete(trxLoggerDirectory, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Call test with logger enable
|
|
|
|
|
CommandResult result = new DotnetTestCommand()
|
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
2016-12-30 15:34:00 +05:30
|
|
|
|
.ExecuteWithCapturedOutput("--logger \"trx;logfilename=custom.trx\" -- RunConfiguration.ResultsDirectory=" + trxLoggerDirectory);
|
2016-12-30 11:24:03 +05:30
|
|
|
|
|
|
|
|
|
// Verify
|
2017-03-25 15:18:14 +05:30
|
|
|
|
var trxFilePath = Path.Combine(trxLoggerDirectory, "custom.trx");
|
|
|
|
|
Assert.True(File.Exists(trxFilePath));
|
|
|
|
|
result.StdOut.Should().Contain(trxFilePath);
|
2016-12-30 11:24:03 +05:30
|
|
|
|
|
|
|
|
|
// Cleanup trxLoggerDirectory if it exist
|
|
|
|
|
if (Directory.Exists(trxLoggerDirectory))
|
|
|
|
|
{
|
|
|
|
|
Directory.Delete(trxLoggerDirectory, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-18 00:45:25 -08:00
|
|
|
|
[Fact(Skip = "https://github.com/dotnet/cli/issues/5035")]
|
|
|
|
|
public void ItBuildsAndTestsAppWhenRestoringToSpecificDirectory()
|
|
|
|
|
{
|
|
|
|
|
var rootPath = TestAssets.Get("VSTestDotNetCore").CreateInstance().WithSourceFiles().Root.FullName;
|
|
|
|
|
|
|
|
|
|
string dir = "pkgs";
|
|
|
|
|
string fullPath = Path.GetFullPath(Path.Combine(rootPath, dir));
|
|
|
|
|
|
|
|
|
|
string args = $"--packages \"{dir}\"";
|
|
|
|
|
new RestoreCommand()
|
|
|
|
|
.WithWorkingDirectory(rootPath)
|
|
|
|
|
.Execute(args)
|
|
|
|
|
.Should()
|
|
|
|
|
.Pass();
|
|
|
|
|
|
|
|
|
|
new BuildCommand()
|
|
|
|
|
.WithWorkingDirectory(rootPath)
|
|
|
|
|
.ExecuteWithCapturedOutput()
|
|
|
|
|
.Should()
|
|
|
|
|
.Pass()
|
|
|
|
|
.And.NotHaveStdErr();
|
|
|
|
|
|
|
|
|
|
CommandResult result = new DotnetTestCommand()
|
|
|
|
|
.WithWorkingDirectory(rootPath)
|
2017-02-18 23:05:33 +05:30
|
|
|
|
.ExecuteWithCapturedOutput(TestBase.ConsoleLoggerOutputNormal);
|
2016-12-18 00:45:25 -08:00
|
|
|
|
|
|
|
|
|
result.StdOut.Should().Contain("Total tests: 2. Passed: 1. Failed: 1. Skipped: 0.");
|
|
|
|
|
result.StdOut.Should().Contain("Passed TestNamespace.VSTestTests.VSTestPassTest");
|
|
|
|
|
result.StdOut.Should().Contain("Failed TestNamespace.VSTestTests.VSTestFailTest");
|
|
|
|
|
}
|
2017-03-25 15:18:14 +05:30
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2016-10-04 15:37:36 +05:30
|
|
|
|
}
|
2016-12-16 15:39:52 +05:30
|
|
|
|
}
|