Merge pull request #4491 from Faizan2304/test3formultipletfm
Test3 verb for multiple TFM
This commit is contained in:
commit
31656f0e4e
9 changed files with 270 additions and 11 deletions
40
TestAssets/TestProjects/VSTestDesktopAndNetCoreApp/Tests.cs
Normal file
40
TestAssets/TestProjects/VSTestDesktopAndNetCoreApp/Tests.cs
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
|
||||||
|
namespace TestNamespace
|
||||||
|
{
|
||||||
|
public class Program
|
||||||
|
{
|
||||||
|
public static void Main(string[] args)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestClass]
|
||||||
|
public class VSTestTests
|
||||||
|
{
|
||||||
|
[TestMethod]
|
||||||
|
public void VSTestPassTest()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void VSTestFailTest()
|
||||||
|
{
|
||||||
|
Assert.Fail();
|
||||||
|
}
|
||||||
|
|
||||||
|
#if DESKTOP
|
||||||
|
[TestMethod]
|
||||||
|
public void VSTestPassTestDesktop()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
[TestMethod]
|
||||||
|
public void VSTestFailTestNetCoreApp()
|
||||||
|
{
|
||||||
|
Assert.Fail();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFrameworks>net46</TargetFrameworks>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup Condition="'$(TargetFramework)' == 'net46'">
|
||||||
|
<DefineConstants>DESKTOP;$(DefineConstants)</DefineConstants>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="**\*.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp1.0'">
|
||||||
|
<PackageReference Include="Microsoft.NETCore.App">
|
||||||
|
<Version>1.0.1</Version>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.NET.Sdk">
|
||||||
|
<Version>1.0.0-alpha-20161026-2</Version>
|
||||||
|
<PrivateAssets>All</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="MSTest.TestFramework">
|
||||||
|
<Version>1.0.5-preview</Version>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="MSTest.TestAdapter">
|
||||||
|
<Version>1.1.4-preview</Version>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.TestPlatform.TestHost">
|
||||||
|
<Version>15.0.0-preview-20161028-03</Version>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildExtensionsPath)\Microsoft.CSharp.targets" />
|
||||||
|
</Project>
|
|
@ -5,7 +5,6 @@
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFrameworks>netcoreapp1.0</TargetFrameworks>
|
<TargetFrameworks>netcoreapp1.0</TargetFrameworks>
|
||||||
<OutputPath>bin\$(Configuration)</OutputPath>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -21,13 +20,13 @@
|
||||||
<PrivateAssets>All</PrivateAssets>
|
<PrivateAssets>All</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="MSTest.TestFramework">
|
<PackageReference Include="MSTest.TestFramework">
|
||||||
<Version>1.0.4-preview</Version>
|
<Version>1.0.5-preview</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="MSTest.TestAdapter">
|
<PackageReference Include="MSTest.TestAdapter">
|
||||||
<Version>1.1.3-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-20161005-01</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" />
|
||||||
|
|
|
@ -171,7 +171,10 @@
|
||||||
<!-- Crossgen the Shared Framework -->
|
<!-- Crossgen the Shared Framework -->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<SdkFiles Remove="*" />
|
<SdkFiles Remove="*" />
|
||||||
<SdkFiles Include="$(SdkOutputDirectory)/**/*" />
|
|
||||||
|
<!-- Removing Full CLR built TestHost assemblies from getting Crossgen as it is throwing error -->
|
||||||
|
<SdkFilesExclude Include="$(SdkOutputDirectory)/TestHost*/**/*" />
|
||||||
|
<SdkFiles Include="$(SdkOutputDirectory)/**/*" Exclude="@(SdkFilesExclude)" />
|
||||||
<SdkFilesWithPEMarker Remove="*" />
|
<SdkFilesWithPEMarker Remove="*" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@ -216,8 +219,6 @@
|
||||||
<Copy SourceFiles="@(MSBuildTargetsToCopy)"
|
<Copy SourceFiles="@(MSBuildTargetsToCopy)"
|
||||||
DestinationFiles="@(MSBuildTargetsToCopy->'$(SdkOutputDirectory)/%(RecursiveDir)%(Filename)%(Extension)')" />
|
DestinationFiles="@(MSBuildTargetsToCopy->'$(SdkOutputDirectory)/%(RecursiveDir)%(Filename)%(Extension)')" />
|
||||||
|
|
||||||
<RemoveDir Directories="$(SdkOutputDirectory)/Extensions" />
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<FilesToClean Include="$(StageDirectory)/sdk/**/vbc.exe" />
|
<FilesToClean Include="$(StageDirectory)/sdk/**/vbc.exe" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
<!--
|
||||||
|
***********************************************************************************************
|
||||||
|
Microsoft.TestPlatform.CrossTargeting.targets
|
||||||
|
|
||||||
|
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
|
||||||
|
created a backup copy. Incorrect changes to this file will make it
|
||||||
|
impossible to load or build your projects from the command-line or the IDE.
|
||||||
|
|
||||||
|
Copyright (c) .NET Foundation. All rights reserved.
|
||||||
|
***********************************************************************************************
|
||||||
|
-->
|
||||||
|
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
|
||||||
|
<!--
|
||||||
|
===================================================================================
|
||||||
|
DispatchToInnerBuildsWithVSTestTarget
|
||||||
|
|
||||||
|
Builds this project with /t:$(InnerVSTestTargets) /p:TargetFramework=X for each
|
||||||
|
value X in $(TargetFrameworks)
|
||||||
|
|
||||||
|
[IN]
|
||||||
|
$(TargetFrameworks) - Semicolon delimited list of target frameworks.
|
||||||
|
$(InnerVSTestTargets) - The targets to build for each target framework
|
||||||
|
|
||||||
|
[OUT]
|
||||||
|
@(InnerOutput) - The combined output items of inner targets across
|
||||||
|
all target frameworks..
|
||||||
|
|
||||||
|
===================================================================================
|
||||||
|
-->
|
||||||
|
|
||||||
|
<Target Name="DispatchToInnerBuildsWithVSTestTarget" Returns="@(InnerOutput)">
|
||||||
|
<ItemGroup>
|
||||||
|
<_TargetFramework Include="$(TargetFrameworks)" />
|
||||||
|
</ItemGroup>
|
||||||
|
<MSBuild Projects="$(MSBuildProjectFile)"
|
||||||
|
Condition="'$(TargetFrameworks)' != '' "
|
||||||
|
Targets="$(InnerVSTestTargets)"
|
||||||
|
Properties="TargetFramework=%(_TargetFramework.Identity);VSTestNoBuild=true">
|
||||||
|
<Output ItemName="InnerOutput" TaskParameter="TargetOutputs" />
|
||||||
|
</MSBuild>
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
==================================================================================
|
||||||
|
VSTest
|
||||||
|
|
||||||
|
Cross-targeting version of VSTest.
|
||||||
|
|
||||||
|
[IN]
|
||||||
|
$(TargetFrameworks) - Semicolon delimited list of target frameworks.
|
||||||
|
$(InnerVSTestTargets) - The targets to build for each target framework. Defaults
|
||||||
|
to 'VSTest' if unset, but allows override to support
|
||||||
|
`msbuild /p:InnerTargets=X;Y;Z` which will build X, Y,
|
||||||
|
and Z targets for each target framework.
|
||||||
|
|
||||||
|
[OUT]
|
||||||
|
@(InnerOutput) - The combined output items of the inner targets across
|
||||||
|
all builds.
|
||||||
|
=================================================================================
|
||||||
|
-->
|
||||||
|
<Target Name="VSTest" >
|
||||||
|
<CallTarget Condition="'$(VSTestNoBuild)' != 'true'" Targets="Build" />
|
||||||
|
<CallTarget Targets="SetVSTestInnerTarget" />
|
||||||
|
<CallTarget Targets="DispatchToInnerBuildsWithVSTestTarget" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<Target Name="SetVSTestInnerTarget" Returns="@(InnerOutput)">
|
||||||
|
<PropertyGroup Condition="'$(InnerVSTestTargets)' == ''">
|
||||||
|
<InnerVSTestTargets>VSTest</InnerVSTestTargets>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Target>
|
||||||
|
</Project>
|
|
@ -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");
|
||||||
|
|
|
@ -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-20161005-01",
|
"Microsoft.TestPlatform.CLI": "15.0.0-preview-20161028-03",
|
||||||
"Microsoft.TestPlatform.Build": "15.0.0-preview-20161005-01"
|
"Microsoft.TestPlatform.Build": "15.0.0-preview-20161028-03"
|
||||||
},
|
},
|
||||||
"frameworks": {
|
"frameworks": {
|
||||||
"netcoreapp1.0": {
|
"netcoreapp1.0": {
|
||||||
|
|
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,12 +6,14 @@ using Xunit;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Microsoft.DotNet.TestFramework;
|
using Microsoft.DotNet.TestFramework;
|
||||||
using Microsoft.DotNet.Cli.Utils;
|
using Microsoft.DotNet.Cli.Utils;
|
||||||
|
using System.IO;
|
||||||
|
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
|
||||||
|
@ -37,5 +39,35 @@ 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");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//[Fact]
|
||||||
|
public void TestWillNotBuildTheProjectIfNoBuildArgsIsGiven()
|
||||||
|
{
|
||||||
|
// Copy DotNetCoreTestProject project in output directory of project dotnet-vstest.Tests
|
||||||
|
string testAppName = "VSTestDotNetCoreProject";
|
||||||
|
TestInstance testInstance = TestAssetsManager.CreateTestInstance(testAppName);
|
||||||
|
|
||||||
|
string testProjectDirectory = testInstance.TestRoot;
|
||||||
|
|
||||||
|
// Restore project VSTestDotNetCoreProject
|
||||||
|
new RestoreCommand()
|
||||||
|
.WithWorkingDirectory(testProjectDirectory)
|
||||||
|
.Execute()
|
||||||
|
.Should()
|
||||||
|
.Pass();
|
||||||
|
|
||||||
|
string configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
|
||||||
|
string expectedError = Path.Combine(testProjectDirectory, "bin",
|
||||||
|
configuration, "netcoreapp1.0", "VSTestDotNetCoreProject.dll");
|
||||||
|
expectedError = "The test source file " + "\"" + expectedError + "\"" + " provided was not found.";
|
||||||
|
|
||||||
|
// Call test3
|
||||||
|
CommandResult result = new DotnetTestCommand()
|
||||||
|
.WithWorkingDirectory(testProjectDirectory)
|
||||||
|
.ExecuteWithCapturedOutput("--noBuild");
|
||||||
|
|
||||||
|
// Verify
|
||||||
|
result.StdOut.Should().Contain(expectedError);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue