Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support to run MSTest based tests. #856

Merged
merged 5 commits into from
May 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions build.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
],
"TestAssets": [
"NUnitTestProject",
"XunitTestProject"
"XunitTestProject",
"MSTestProject"
],
"LegacyTestAssets": [
"BasicTestProjectSample01",
"BasicTestProjectSample02",
"LegacyNunitTestProject",
"LegacyXunitTestProject"
"LegacyXunitTestProject",
"LegacyMSTestProject"
]
}
6 changes: 4 additions & 2 deletions src/OmniSharp.DotNetTest/Legacy/LegacyTestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ public override RunTestResponse RunTest(string methodName, string testFrameworkN
var testStartInfo = testStartInfoMessage.DeserializePayload<TestStartInfo>();

var fileName = testStartInfo.FileName;
var arguments = $"{testStartInfo.Arguments} {testFramework.MethodArgument} {methodName}";
// We pass in the tests as a list. So trimming out the wait-command that expects the tests to be sent as a separate message.
var startInfoArguments = testStartInfo.Arguments.Replace("--wait-command", "");
var arguments = $"{startInfoArguments} {testFramework.MethodArgument} {methodName}";

var startInfo = new ProcessStartInfo(fileName, arguments)
{
Expand Down Expand Up @@ -162,7 +164,7 @@ public override GetTestStartInfoResponse GetTestStartInfo(string methodName, str
{
arguments = arguments.Substring(0, endIndex).TrimEnd();
}

if (!string.IsNullOrEmpty(methodName))
{
arguments = $"{arguments} {testFramework.MethodArgument} {methodName}";
Expand Down
14 changes: 14 additions & 0 deletions src/OmniSharp.DotNetTest/TestFrameworks/MSTestFramework.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace OmniSharp.DotNetTest.TestFrameworks
{
internal class MSTestFramework : TestFramework
{
public override string FeatureName { get; } = "MSTestMethod";
public override string Name { get; } = "mstest";
public override string MethodArgument { get; } = "--test";

protected override bool IsTestAttributeName(string typeName)
{
return typeName == "Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute";
}
}
}
2 changes: 2 additions & 0 deletions src/OmniSharp.DotNetTest/TestFrameworks/TestFramework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ static TestFramework()

var nunit = new NUnitTestFramework();
var xunit = new XunitTestFramework();
var mstest = new MSTestFramework();

builder.Add(nunit.Name, nunit);
builder.Add(xunit.Name, xunit);
builder.Add(mstest.Name, mstest);

s_frameworks = builder.ToImmutable();
}
Expand Down
6 changes: 6 additions & 0 deletions test-assets/test-projects/LegacyMSTestProject/NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
35 changes: 35 additions & 0 deletions test-assets/test-projects/LegacyMSTestProject/TestProgram.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Main.Test
{
[TestClass]
public class MainTest
{
[TestMethod]
public void Test()
{
Assert.IsTrue(true);
}

[TestMethod]
[DataRow(0)]
[DataRow(1)]
public void DataDrivenTest1(int i)
{
Assert.IsTrue(i > 0);
}

[TestMethod]
[DataRow(0)]
[DataRow(1)]
public void DataDrivenTest2(int i)
{
Assert.IsTrue(i >= 0);
}

private void UtilityFunction()
{

}
}
}
30 changes: 30 additions & 0 deletions test-assets/test-projects/LegacyMSTestProject/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"version": "1.0.0-*",
"dependencies": {
"MSTest.TestFramework": "1.0.7-preview",
"dotnet-test-mstest": "1.1.2-preview",
"Microsoft.NETCore.App": "1.0.0"
},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {},
"imports": [
"dnxcore50",
"portable-net45+win8"
]
}
},
"runtimes": {
"win7-x64": {},
"win7-x86": {},
"osx.10.11-x64": {},
"ubuntu.14.04-x64": {},
"ubuntu.16.04-x64": {},
"centos.7-x64": {},
"rhel.7.2-x64": {},
"debian.8-x64": {},
"fedora.23-x64": {},
"opensuse.13.2-x64": {}
},
"testRunner": "mstest"
}
13 changes: 13 additions & 0 deletions test-assets/test-projects/MSTestProject/MSTestProject.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.1.17" />
<PackageReference Include="MSTest.TestFramework" Version="1.1.17" />
</ItemGroup>

</Project>
35 changes: 35 additions & 0 deletions test-assets/test-projects/MSTestProject/TestProgram.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Main.Test
{
[TestClass]
public class MainTest
{
[TestMethod]
public void Test()
{
Assert.IsTrue(true);
}

[TestMethod]
[DataRow(0)]
[DataRow(1)]
public void DataDrivenTest1(int i)
{
Assert.IsTrue(i > 0);
}

[TestMethod]
[DataRow(0)]
[DataRow(1)]
public void DataDrivenTest2(int i)
{
Assert.IsTrue(i >= 0);
}

private void UtilityFunction()
{

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ public abstract class AbstractGetTestStartInfoFacts : AbstractTestFixture
{
protected const string LegacyXunitTestProject = "LegacyXunitTestProject";
protected const string LegacyNunitTestProject = "LegacyNunitTestProject";
protected const string LegacyMSTestProject = "LegacyMSTestProject";
protected const string XunitTestProject = "XunitTestProject";
protected const string NunitTestProject = "NunitTestProject";
protected const string MSTestProject = "MSTestProject";

protected AbstractGetTestStartInfoFacts(ITestOutputHelper output)
: base(output)
Expand Down
2 changes: 2 additions & 0 deletions tests/OmniSharp.DotNetTest.Tests/AbstractRunTestFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ public abstract class AbstractRunTestFacts : AbstractTestFixture
{
protected const string LegacyXunitTestProject = "LegacyXunitTestProject";
protected const string LegacyNunitTestProject = "LegacyNunitTestProject";
protected const string LegacyMSTestProject = "LegacyMSTestProject";
protected const string XunitTestProject = "XunitTestProject";
protected const string NUnitTestProject = "NUnitTestProject";
protected const string MSTestProject = "MSTestProject";

public AbstractRunTestFacts(ITestOutputHelper testOutput)
: base(testOutput)
Expand Down
9 changes: 9 additions & 0 deletions tests/OmniSharp.DotNetTest.Tests/GetTestStartInfoFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,14 @@ await GetDotNetTestStartInfoAsync(
methodName: "Main.Test.MainTest.Test",
testFramework: "nunit");
}

[Fact]
public async Task RunMSTestTest()
{
await GetDotNetTestStartInfoAsync(
MSTestProject,
methodName: "Main.Test.MainTest.Test",
testFramework: "mstest");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,14 @@ await GetDotNetTestStartInfoAsync(
methodName: "Main.Test.MainTest.Test",
testFramework: "nunit");
}

[Fact]
public async Task RunMSTestTest()
{
await GetDotNetTestStartInfoAsync(
LegacyMSTestProject,
methodName: "Main.Test.MainTest.Test",
testFramework: "mstest");
}
}
}
31 changes: 31 additions & 0 deletions tests/OmniSharp.DotNetTest.Tests/LegacyRunTestFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Xunit;
using Xunit.Abstractions;


namespace OmniSharp.DotNetTest.Tests
{
/// <summary>
Expand Down Expand Up @@ -85,5 +86,35 @@ await RunDotNetTestAsync(
testFramework: "nunit",
shouldPass: true);
}

[Fact]
public async Task RunMSTest()
{
await RunDotNetTestAsync(
LegacyMSTestProject,
methodName: "Main.Test.MainTest.Test",
testFramework: "mstest",
shouldPass: true);
}

[Fact]
public async Task RunMSTestDataDriveTest1()
{
await RunDotNetTestAsync(
LegacyMSTestProject,
methodName: "Main.Test.MainTest.DataDrivenTest1",
testFramework: "mstest",
shouldPass: false);
}

[Fact]
public async Task RunMSTestDataDriveTest2()
{
await RunDotNetTestAsync(
LegacyMSTestProject,
methodName: "Main.Test.MainTest.DataDrivenTest2",
testFramework: "mstest",
shouldPass: true);
}
}
}
30 changes: 30 additions & 0 deletions tests/OmniSharp.DotNetTest.Tests/RunTestFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,35 @@ await RunDotNetTestAsync(
testFramework: "nunit",
shouldPass: true);
}

[Fact]
public async Task RunMSTestTest()
{
await RunDotNetTestAsync(
MSTestProject,
methodName: "Main.Test.MainTest.Test",
testFramework: "mstest",
shouldPass: true);
}

[Fact]
public async Task RunMSTestDataDriveTest1()
{
await RunDotNetTestAsync(
MSTestProject,
methodName: "Main.Test.MainTest.DataDrivenTest1",
testFramework: "mstest",
shouldPass: false);
}

[Fact]
public async Task RunMSTestDataDriveTest2()
{
await RunDotNetTestAsync(
MSTestProject,
methodName: "Main.Test.MainTest.DataDrivenTest2",
testFramework: "mstest",
shouldPass: true);
}
}
}