Implemented vstest verb which will run the test from given container. (#4115)

* Implemented vstest verb which will run the test from given container.

* Fixed Nitpick.

* 1) Addressed PR comment
2) Added tests for vstest verb

* Using specific version of Microsoft.TestPlatform.

* Address PR comments.

Modified help text for the vstest command.
Removed unused function.

* Fixed package related issue.
--Taking reference of microsoft.testplatform.cli nuget package which has contentFolder in it so that sub folder of this nuget can also be added in cli package.
-- Removing vstest.console, vshost and datacollector from Bundletools as we dont want *.deps.json to be override

* Nitpick

* Making vstest.console arguments compatible for non windows platform

* Fix tests to run on linux machine

* Updated the microsoft.testplatform.cli nuget package version. This version has fix related to non windows machine.

* changed dapter path from bin/debug to bin/Debug

* updated nuget version of package Microsoft.TestPlatform.CLI.

* Revert "updated nuget version of package Microsoft.TestPlatform.CLI."

This reverts commit bcc26c21d11c2bd2e5259a74f9890b0fd75962c7.

* Updated version of nuget package Microsoft.TestPlatform.CLI
Added Test project in solution file

* Addressed PR comment.

* Removed unnecessary --platform argument from test
This commit is contained in:
Faizan2304 2016-09-19 23:29:26 +05:30 committed by Livar
parent 5b48f22145
commit 0ce597a147
13 changed files with 259 additions and 2 deletions

View file

@ -166,6 +166,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dotnet-migrate.Tests", "tes
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.DotNet.Tools.Test", "src\Microsoft.DotNet.Tools.Test\Microsoft.DotNet.Tools.Test.xproj", "{6D028154-5518-4A56-BAD6-938A90E5BCF6}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dotnet-vstest.Tests", "test\dotnet-vstest.Tests\dotnet-vstest.Tests.xproj", "{9F5AE280-A040-4160-9799-6504D907742D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -946,6 +948,22 @@ Global
{6D028154-5518-4A56-BAD6-938A90E5BCF6}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
{6D028154-5518-4A56-BAD6-938A90E5BCF6}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
{6D028154-5518-4A56-BAD6-938A90E5BCF6}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
{9F5AE280-A040-4160-9799-6504D907742D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9F5AE280-A040-4160-9799-6504D907742D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9F5AE280-A040-4160-9799-6504D907742D}.Debug|x64.ActiveCfg = Debug|Any CPU
{9F5AE280-A040-4160-9799-6504D907742D}.Debug|x64.Build.0 = Debug|Any CPU
{9F5AE280-A040-4160-9799-6504D907742D}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
{9F5AE280-A040-4160-9799-6504D907742D}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
{9F5AE280-A040-4160-9799-6504D907742D}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
{9F5AE280-A040-4160-9799-6504D907742D}.MinSizeRel|x64.Build.0 = Debug|Any CPU
{9F5AE280-A040-4160-9799-6504D907742D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9F5AE280-A040-4160-9799-6504D907742D}.Release|Any CPU.Build.0 = Release|Any CPU
{9F5AE280-A040-4160-9799-6504D907742D}.Release|x64.ActiveCfg = Release|Any CPU
{9F5AE280-A040-4160-9799-6504D907742D}.Release|x64.Build.0 = Release|Any CPU
{9F5AE280-A040-4160-9799-6504D907742D}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU
{9F5AE280-A040-4160-9799-6504D907742D}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
{9F5AE280-A040-4160-9799-6504D907742D}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
{9F5AE280-A040-4160-9799-6504D907742D}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -1007,5 +1025,6 @@ Global
{0E083818-2320-4388-8007-4F720FD5C634} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F}
{1F2EF070-AC5F-4078-AFB0-65745AC691B9} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
{6D028154-5518-4A56-BAD6-938A90E5BCF6} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F}
{9F5AE280-A040-4160-9799-6504D907742D} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
EndGlobalSection
EndGlobal

View file

@ -0,0 +1,19 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace TestNamespace
{
[TestClass]
public class VSTestTests
{
[TestMethod]
public void VSTestPassTest()
{
}
[TestMethod]
public void VSTestFailTest()
{
Assert.Fail();
}
}
}

View file

@ -0,0 +1,25 @@
<?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>Library</OutputType>
<TargetFrameworkIdentifier>.NETCoreApp</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
<OutputPath>bin\$(Configuration)\netcoreapp1.0</OutputPath>
</PropertyGroup>
<ItemGroup>
<Compile Include="**\*.cs" />
<None Include="project.json" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft.CSharp.targets" />
<Target Name="AfterBuild">
<Copy SourceFiles="$(NuGetPackageRoot)\mstest.testadapter\1.0.3-preview\build\_common\Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll" DestinationFolder="$(OutputPath)" SkipUnchangedFiles="true"/>
<Copy SourceFiles="$(NuGetPackageRoot)\mstest.testadapter\1.0.3-preview\build\dotnet\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll" DestinationFolder="$(OutputPath)" SkipUnchangedFiles="true"/>
<Copy SourceFiles="$(NuGetPackageRoot)\mstest.testadapter\1.0.3-preview\build\_common\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.dll" DestinationFolder="$(OutputPath)" SkipUnchangedFiles="true"/>
<Copy SourceFiles="$(NuGetPackageRoot)\mstest.testframework\1.0.1-preview\lib\dotnet\Microsoft.VisualStudio.TestPlatform.TestFramework.dll" DestinationFolder="$(OutputPath)" SkipUnchangedFiles="true"/>
<Copy SourceFiles="$(NuGetPackageRoot)\mstest.testframework\1.0.1-preview\lib\dotnet\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll" DestinationFolder="$(OutputPath)" SkipUnchangedFiles="true"/>
</Target>
</Project>

View file

@ -0,0 +1,21 @@
{
"dependencies": {
"MSTest.TestAdapter": "1.0.3-preview",
"MSTest.TestFramework": "1.0.1-preview"
},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.Sdk": "1.0.0-alpha-20160914-1",
"Microsoft.NETCore.App": {
"version": "1.0.1",
"type": "platform"
}
},
"imports": [
"dnxcore50",
"portable-net45+win8"
]
}
}
}

View file

@ -23,6 +23,7 @@ using Microsoft.DotNet.Tools.Restore;
using Microsoft.DotNet.Tools.Restore3;
using Microsoft.DotNet.Tools.Run;
using Microsoft.DotNet.Tools.Test;
using Microsoft.DotNet.Tools.VSTest;
using Microsoft.DotNet.Tools.Migrate;
using NuGet.Frameworks;
@ -45,6 +46,7 @@ namespace Microsoft.DotNet.Cli
["build3"] = Build3Command.Run,
["run3"] = Run3Command.Run,
["restore3"] = Restore3Command.Run,
["vstest"] = VSTestCommand.Run,
["pack3"] = Pack3Command.Run,
["migrate"] = MigrateCommand.Run,
["projectmodel-server"] = ProjectModelServerCommand.Run,

View file

@ -32,7 +32,8 @@ Commands:
publish Publishes a .NET project for deployment (including the runtime)
run Compiles and immediately executes a .NET project
test Runs unit tests using the test runner specified in the project
pack Creates a NuGet package";
pack Creates a NuGet package
vstest Runs tests from the specified files";
public static int Run(string[] args)
{

View file

@ -0,0 +1,17 @@
// 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.Cli.Utils;
using Microsoft.DotNet.Cli;
namespace Microsoft.DotNet.Tools.VSTest
{
public class VSTestCommand
{
public static int Run(string[] args)
{
DebugHelper.HandleDebugSwitch(ref args);
return new VSTestForwardingApp(args).Execute();
}
}
}

View file

@ -0,0 +1,33 @@
// 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.Cli.Utils;
using System;
using System.Collections.Generic;
using System.IO;
namespace Microsoft.DotNet.Cli
{
public class VSTestForwardingApp
{
private const string VstestAppName = "vstest.console.dll";
private readonly ForwardingApp _forwardingApp;
public VSTestForwardingApp(IEnumerable<string> argsToForward)
{
_forwardingApp = new ForwardingApp(
GetVSTestExePath(),
argsToForward);
}
public int Execute()
{
return _forwardingApp.Execute();
}
private string GetVSTestExePath()
{
return Path.Combine(AppContext.BaseDirectory, VstestAppName);
}
}
}

View file

@ -20,7 +20,8 @@
"Microsoft.Build.Targets": "0.1.0-preview-00038-160914",
"Microsoft.Build": "0.1.0-preview-00038-160914",
"System.Runtime.Serialization.Xml": "4.1.0",
"NuGet.Build.Tasks": "3.6.0-beta.1.msbuild.9"
"NuGet.Build.Tasks": "3.6.0-beta.1.msbuild.9",
"Microsoft.TestPlatform.CLI": "15.0.0-preview-20160915-01"
},
"frameworks": {
"netcoreapp1.0": {

View file

@ -0,0 +1,27 @@
// 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.Cli.Utils;
namespace Microsoft.DotNet.Tools.Test.Utilities
{
public sealed class VSTestCommand: TestCommand
{
public VSTestCommand()
:base("dotnet")
{
}
public override CommandResult Execute(string args = "")
{
args = $"vstest {args}";
return base.Execute(args);
}
public override CommandResult ExecuteWithCapturedOutput(string args = "")
{
args = $"vstest {args}";
return base.ExecuteWithCapturedOutput(args);
}
}
}

View file

@ -0,0 +1,47 @@
// 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 System;
using System.IO;
using FluentAssertions;
using Microsoft.DotNet.TestFramework;
using Microsoft.DotNet.Cli.Utils;
namespace Microsoft.DotNet.Cli.VSTest.Tests
{
public class VSTestTests: TestBase
{
[Fact]
public void TestsFromAGivenContainerShouldRunWithExpectedOutput()
{
// Copy DotNetCoreTestProject project in output directory of project dotnet-vstest.Tests
string testAppName = "VSTestDotNetCoreProject";
TestInstance testInstance = TestAssetsManager.CreateTestInstance(testAppName).WithLockFiles();
string testProjectDirectory = testInstance.TestRoot;
// Build project DotNetCoreTestProject
new Build3Command()
.WithWorkingDirectory(testProjectDirectory)
.Execute()
.Should()
.Pass();
// Prepare args to send vstest
string configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
string testAdapterPath = Path.Combine(testProjectDirectory, "bin", configuration, "netcoreapp1.0");
string outputDll = Path.Combine(testAdapterPath, $"{testAppName}.dll");
string argsForVstest = string.Concat("\"", outputDll, "\"", " --TestAdapterPath:", "\"", testAdapterPath, "\"");
// Call vstest
CommandResult result = new VSTestCommand().ExecuteWithCapturedOutput(argsForVstest);
// 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");
}
}
}

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0.23107" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.23107</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>9f5ae280-a040-4160-9799-6504d907742d</ProjectGuid>
<RootNamespace>Microsoft.DotNet.Cli.VSTest.Tests</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View file

@ -0,0 +1,24 @@
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
},
"System.Runtime.Serialization.Primitives": "4.1.1",
"Microsoft.DotNet.Tools.Tests.Utilities": {
"target": "project"
},
"xunit": "2.2.0-beta3-build3330",
"dotnet-test-xunit": "1.0.0-rc2-330423-54"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.4",
"portable-net451+win8"
]
}
},
"testRunner": "xunit"
}