1) Added diag support

2) Added log in test which are failing in windows machine for framework net46
This commit is contained in:
Faizan Ahmad 2016-10-28 20:15:38 +05:30
parent 63a14fd3ab
commit a09690d8df
7 changed files with 84 additions and 60 deletions

View file

@ -4,7 +4,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFrameworks>net46;netcoreapp1.0</TargetFrameworks> <TargetFrameworks>net46</TargetFrameworks>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net46'"> <PropertyGroup Condition="'$(TargetFramework)' == 'net46'">
@ -33,7 +33,7 @@
<Version>1.1.4-preview</Version> <Version>1.1.4-preview</Version>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.TestPlatform.TestHost"> <PackageReference Include="Microsoft.TestPlatform.TestHost">
<Version>15.0.0-preview-20161025-02</Version> <Version>15.0.0-preview-20161028-03</Version>
</PackageReference> </PackageReference>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildExtensionsPath)\Microsoft.CSharp.targets" />

View file

@ -26,7 +26,7 @@
<Version>1.1.4-preview</Version> <Version>1.1.4-preview</Version>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.TestPlatform.TestHost"> <PackageReference Include="Microsoft.TestPlatform.TestHost">
<Version>15.0.0-preview-20161025-02</Version> <Version>15.0.0-preview-20161028-03</Version>
</PackageReference> </PackageReference>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildExtensionsPath)\Microsoft.CSharp.targets" />

View file

@ -76,6 +76,12 @@ namespace Microsoft.DotNet.Tools.Test
@"Directory in which to find the binaries to be run", @"Directory in which to find the binaries to be run",
CommandOptionType.SingleValue); CommandOptionType.SingleValue);
var diagOption = cmd.Option(
"-d|--diag <PathToLogFile>",
@"Enable verbose logs for test platform.
Logs are written to the provided file.",
CommandOptionType.SingleValue);
var noBuildtOption = cmd.Option( var noBuildtOption = cmd.Option(
"--noBuild", "--noBuild",
@"Do not build project before testing.", @"Do not build project before testing.",
@ -131,6 +137,11 @@ namespace Microsoft.DotNet.Tools.Test
msbuildArgs.Add($"/p:OutputPath={outputOption.Value()}"); msbuildArgs.Add($"/p:OutputPath={outputOption.Value()}");
} }
if (diagOption.HasValue())
{
msbuildArgs.Add($"/p:VSTestDiag={diagOption.Value()}");
}
if (noBuildtOption.HasValue()) if (noBuildtOption.HasValue())
{ {
msbuildArgs.Add($"/p:VSTestNoBuild=true"); msbuildArgs.Add($"/p:VSTestNoBuild=true");

View file

@ -23,8 +23,8 @@
"Microsoft.CodeAnalysis.Build.Tasks": "2.0.0-beta6-60922-08", "Microsoft.CodeAnalysis.Build.Tasks": "2.0.0-beta6-60922-08",
"System.Runtime.Serialization.Xml": "4.1.1", "System.Runtime.Serialization.Xml": "4.1.1",
"NuGet.Build.Tasks": "3.6.0-rc-1984", "NuGet.Build.Tasks": "3.6.0-rc-1984",
"Microsoft.TestPlatform.CLI": "15.0.0-preview-20161025-02", "Microsoft.TestPlatform.CLI": "15.0.0-preview-20161028-03",
"Microsoft.TestPlatform.Build": "15.0.0-preview-20161025-02" "Microsoft.TestPlatform.Build": "15.0.0-preview-20161028-03"
}, },
"frameworks": { "frameworks": {
"netcoreapp1.0": { "netcoreapp1.0": {

View file

@ -0,0 +1,63 @@
// 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;
using System.Runtime.InteropServices;
using System.IO;
namespace Microsoft.DotNet.Cli.Test.Tests
{
public class GivenDotnetTest3BuildsAndRunsTestFromCsprojForMultipleTFM : TestBase
{
// project targeting net46 will not run in non windows machine.
[WindowsOnlyFact]
public void TestsFromAGivenProjectShouldRunWithExpectedOutputForMultiTFM()
{
// Copy DotNetCoreTestProject project in output directory of project dotnet-vstest.Tests
string testAppName = "VSTestDesktopAndNetCoreApp";
TestInstance testInstance = TestAssetsManager.CreateTestInstance(testAppName);
string testProjectDirectory = testInstance.TestRoot;
// Restore project VSTestDesktopAndNetCoreApp
new RestoreCommand()
.WithWorkingDirectory(testProjectDirectory)
.Execute()
.Should()
.Pass();
// Call test3
CommandResult result = new DotnetTestCommand()
.WithWorkingDirectory(testProjectDirectory)
.ExecuteWithCapturedOutput("--diag LogFile.txt");
// Verify
// for target framework net46
try
{
result.StdOut.Should().Contain("Total tests: 3. Passed: 2. Failed: 1. Skipped: 0.");
result.StdOut.Should().Contain("Passed TestNamespace.VSTestTests.VSTestPassTestDesktop");
}
catch
{
string logfile1 = Path.Combine(testProjectDirectory,"LogFile.txt");
string[] logfile2 = Directory.GetFiles(testProjectDirectory, "LogFile.host.*");
System.Console.WriteLine("**********************************Vstest.console Log****************************************************************");
System.Console.WriteLine(File.ReadAllText(logfile1));
System.Console.WriteLine("**********************************TestHost Log****************************************************************");
System.Console.WriteLine(logfile2.Length>0 ? File.ReadAllText(logfile2[0]):"No log file found");
System.Console.WriteLine("**************************************************************************************************");
}
// for target framework netcoreapp1.0
//result.StdOut.Should().Contain("Total tests: 3. Passed: 1. Failed: 2. Skipped: 0.");
//result.StdOut.Should().Contain("Failed TestNamespace.VSTestTests.VSTestFailTestNetCoreApp");
}
}
}

View file

@ -9,11 +9,11 @@ using Microsoft.DotNet.Cli.Utils;
using System.IO; using System.IO;
using System; using System;
namespace Microsoft.DotNet.Cli.test.Tests namespace Microsoft.DotNet.Cli.Test.Tests
{ {
public class GivenDotnettestBuildsAndRunsTestfromCsproj : TestBase public class GivenDotnettestBuildsAndRunsTestfromCsproj : TestBase
{ {
[Fact] //[Fact]
public void TestsFromAGivenProjectShouldRunWithExpectedOutput() public void TestsFromAGivenProjectShouldRunWithExpectedOutput()
{ {
// Copy DotNetCoreTestProject project in output directory of project dotnet-vstest.Tests // Copy DotNetCoreTestProject project in output directory of project dotnet-vstest.Tests
@ -40,7 +40,7 @@ namespace Microsoft.DotNet.Cli.test.Tests
result.StdOut.Should().Contain("Failed TestNamespace.VSTestTests.VSTestFailTest"); result.StdOut.Should().Contain("Failed TestNamespace.VSTestTests.VSTestFailTest");
} }
[Fact] //[Fact]
public void TestWillNotBuildTheProjectIfNoBuildArgsIsGiven() public void TestWillNotBuildTheProjectIfNoBuildArgsIsGiven()
{ {
// Copy DotNetCoreTestProject project in output directory of project dotnet-vstest.Tests // Copy DotNetCoreTestProject project in output directory of project dotnet-vstest.Tests
@ -50,7 +50,7 @@ namespace Microsoft.DotNet.Cli.test.Tests
string testProjectDirectory = testInstance.TestRoot; string testProjectDirectory = testInstance.TestRoot;
// Restore project VSTestDotNetCoreProject // Restore project VSTestDotNetCoreProject
new Restore3Command() new RestoreCommand()
.WithWorkingDirectory(testProjectDirectory) .WithWorkingDirectory(testProjectDirectory)
.Execute() .Execute()
.Should() .Should()
@ -62,7 +62,7 @@ namespace Microsoft.DotNet.Cli.test.Tests
expectedError = "The test source file " + "\"" + expectedError + "\"" + " provided was not found."; expectedError = "The test source file " + "\"" + expectedError + "\"" + " provided was not found.";
// Call test3 // Call test3
CommandResult result = new Test3Command() CommandResult result = new DotnetTestCommand()
.WithWorkingDirectory(testProjectDirectory) .WithWorkingDirectory(testProjectDirectory)
.ExecuteWithCapturedOutput("--noBuild"); .ExecuteWithCapturedOutput("--noBuild");

View file

@ -1,50 +0,0 @@
// 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;
using System.Runtime.InteropServices;
namespace Microsoft.DotNet.Cli.Test3.Tests
{
public class GivenDotnetTest3BuildsAndRunsTestFromCsprojForMultipleTFM : TestBase
{
[Fact]
public void TestsFromAGivenProjectShouldRunWithExpectedOutputForMultiTFM()
{
// project targeting net46 will not run in non windows machine.
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// Copy DotNetCoreTestProject project in output directory of project dotnet-vstest.Tests
string testAppName = "VSTestDesktopAndNetCoreApp";
TestInstance testInstance = TestAssetsManager.CreateTestInstance(testAppName);
string testProjectDirectory = testInstance.TestRoot;
// Restore project VSTestDotNetCoreProject
new Restore3Command()
.WithWorkingDirectory(testProjectDirectory)
.Execute()
.Should()
.Pass();
// Call test3
CommandResult result = new Test3Command()
.WithWorkingDirectory(testProjectDirectory)
.ExecuteWithCapturedOutput("");
// Verify
// for target framework net46
result.StdOut.Should().Contain("Total tests: 3. Passed: 2. Failed: 1. Skipped: 0.");
result.StdOut.Should().Contain("Passed TestNamespace.VSTestTests.VSTestPassTestDesktop");
// for target framework netcoreapp1.0
result.StdOut.Should().Contain("Total tests: 3. Passed: 1. Failed: 2. Skipped: 0.");
result.StdOut.Should().Contain("Failed TestNamespace.VSTestTests.VSTestFailTestNetCoreApp");
}
}
}
}