From 9683497946f96f43d57a76af7781a2a31cbaaf9d Mon Sep 17 00:00:00 2001 From: Abhitej Anoop John Bandi Date: Sat, 13 May 2017 02:35:59 +0530 Subject: [PATCH 1/3] Adding support for MSTest based tests in vscode. --- .../TestFrameworks/MSTestFramework.cs | 15 +++++++++++++++ .../TestFrameworks/TestFramework.cs | 2 ++ 2 files changed, 17 insertions(+) create mode 100644 src/OmniSharp.DotNetTest/TestFrameworks/MSTestFramework.cs diff --git a/src/OmniSharp.DotNetTest/TestFrameworks/MSTestFramework.cs b/src/OmniSharp.DotNetTest/TestFrameworks/MSTestFramework.cs new file mode 100644 index 0000000000..8fd39be3b1 --- /dev/null +++ b/src/OmniSharp.DotNetTest/TestFrameworks/MSTestFramework.cs @@ -0,0 +1,15 @@ +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" + || typeName == "Microsoft.VisualStudio.TestTools.UnitTesting.DataTestMethodAttribute"; + } + } +} diff --git a/src/OmniSharp.DotNetTest/TestFrameworks/TestFramework.cs b/src/OmniSharp.DotNetTest/TestFrameworks/TestFramework.cs index 4815dcd17f..4733410adc 100644 --- a/src/OmniSharp.DotNetTest/TestFrameworks/TestFramework.cs +++ b/src/OmniSharp.DotNetTest/TestFrameworks/TestFramework.cs @@ -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(); } From 3722af1c5ad9e86e054808a69bc6e3058f72626b Mon Sep 17 00:00:00 2001 From: Abhitej Anoop John Bandi Date: Tue, 16 May 2017 01:31:21 +0530 Subject: [PATCH 2/3] Tests and PR comments addressed. The legacy tests however are not running as expected and hence are commented for now. In the process of figuring out why this bombs. --- build.json | 6 ++-- .../TestFrameworks/MSTestFramework.cs | 3 +- .../LegacyMSTestProject/NuGet.Config | 6 ++++ .../LegacyMSTestProject/TestProgram.cs | 35 +++++++++++++++++++ .../LegacyMSTestProject/project.json | 30 ++++++++++++++++ .../MSTestProject/MSTestProject.csproj | 13 +++++++ .../MSTestProject/TestProgram.cs | 35 +++++++++++++++++++ .../AbstractGetTestStartInfoFacts.cs | 2 ++ .../AbstractRunTestFacts.cs | 2 ++ .../GetTestStartInfoFacts.cs | 9 +++++ .../LegacyGetTestStartInfoFacts.cs | 9 +++++ .../LegacyRunTestFacts.cs | 33 +++++++++++++++++ .../RunTestFacts.cs | 30 ++++++++++++++++ 13 files changed, 209 insertions(+), 4 deletions(-) create mode 100644 test-assets/test-projects/LegacyMSTestProject/NuGet.Config create mode 100644 test-assets/test-projects/LegacyMSTestProject/TestProgram.cs create mode 100644 test-assets/test-projects/LegacyMSTestProject/project.json create mode 100644 test-assets/test-projects/MSTestProject/MSTestProject.csproj create mode 100644 test-assets/test-projects/MSTestProject/TestProgram.cs diff --git a/build.json b/build.json index 3755e2eedc..6a88429d83 100644 --- a/build.json +++ b/build.json @@ -21,12 +21,14 @@ ], "TestAssets": [ "NUnitTestProject", - "XunitTestProject" + "XunitTestProject", + "MSTestProject" ], "LegacyTestAssets": [ "BasicTestProjectSample01", "BasicTestProjectSample02", "LegacyNunitTestProject", - "LegacyXunitTestProject" + "LegacyXunitTestProject", + "LegacyMSTestProject" ] } diff --git a/src/OmniSharp.DotNetTest/TestFrameworks/MSTestFramework.cs b/src/OmniSharp.DotNetTest/TestFrameworks/MSTestFramework.cs index 8fd39be3b1..4484ff0935 100644 --- a/src/OmniSharp.DotNetTest/TestFrameworks/MSTestFramework.cs +++ b/src/OmniSharp.DotNetTest/TestFrameworks/MSTestFramework.cs @@ -8,8 +8,7 @@ internal class MSTestFramework : TestFramework protected override bool IsTestAttributeName(string typeName) { - return typeName == "Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute" - || typeName == "Microsoft.VisualStudio.TestTools.UnitTesting.DataTestMethodAttribute"; + return typeName == "Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute"; } } } diff --git a/test-assets/test-projects/LegacyMSTestProject/NuGet.Config b/test-assets/test-projects/LegacyMSTestProject/NuGet.Config new file mode 100644 index 0000000000..21cb6efabd --- /dev/null +++ b/test-assets/test-projects/LegacyMSTestProject/NuGet.Config @@ -0,0 +1,6 @@ + + + + + + diff --git a/test-assets/test-projects/LegacyMSTestProject/TestProgram.cs b/test-assets/test-projects/LegacyMSTestProject/TestProgram.cs new file mode 100644 index 0000000000..832569d94e --- /dev/null +++ b/test-assets/test-projects/LegacyMSTestProject/TestProgram.cs @@ -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() + { + + } + } +} diff --git a/test-assets/test-projects/LegacyMSTestProject/project.json b/test-assets/test-projects/LegacyMSTestProject/project.json new file mode 100644 index 0000000000..a291b55b65 --- /dev/null +++ b/test-assets/test-projects/LegacyMSTestProject/project.json @@ -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" +} diff --git a/test-assets/test-projects/MSTestProject/MSTestProject.csproj b/test-assets/test-projects/MSTestProject/MSTestProject.csproj new file mode 100644 index 0000000000..9b69598a0c --- /dev/null +++ b/test-assets/test-projects/MSTestProject/MSTestProject.csproj @@ -0,0 +1,13 @@ + + + + netcoreapp1.1 + + + + + + + + + diff --git a/test-assets/test-projects/MSTestProject/TestProgram.cs b/test-assets/test-projects/MSTestProject/TestProgram.cs new file mode 100644 index 0000000000..832569d94e --- /dev/null +++ b/test-assets/test-projects/MSTestProject/TestProgram.cs @@ -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() + { + + } + } +} diff --git a/tests/OmniSharp.DotNetTest.Tests/AbstractGetTestStartInfoFacts.cs b/tests/OmniSharp.DotNetTest.Tests/AbstractGetTestStartInfoFacts.cs index e7ee6d2197..53e8d94a5b 100644 --- a/tests/OmniSharp.DotNetTest.Tests/AbstractGetTestStartInfoFacts.cs +++ b/tests/OmniSharp.DotNetTest.Tests/AbstractGetTestStartInfoFacts.cs @@ -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) diff --git a/tests/OmniSharp.DotNetTest.Tests/AbstractRunTestFacts.cs b/tests/OmniSharp.DotNetTest.Tests/AbstractRunTestFacts.cs index fc52e02c59..c5428b4d54 100644 --- a/tests/OmniSharp.DotNetTest.Tests/AbstractRunTestFacts.cs +++ b/tests/OmniSharp.DotNetTest.Tests/AbstractRunTestFacts.cs @@ -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) diff --git a/tests/OmniSharp.DotNetTest.Tests/GetTestStartInfoFacts.cs b/tests/OmniSharp.DotNetTest.Tests/GetTestStartInfoFacts.cs index 3dee03b3c6..bcafee96ff 100644 --- a/tests/OmniSharp.DotNetTest.Tests/GetTestStartInfoFacts.cs +++ b/tests/OmniSharp.DotNetTest.Tests/GetTestStartInfoFacts.cs @@ -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"); + } } } diff --git a/tests/OmniSharp.DotNetTest.Tests/LegacyGetTestStartInfoFacts.cs b/tests/OmniSharp.DotNetTest.Tests/LegacyGetTestStartInfoFacts.cs index 1d5401a0c0..8d013e4adb 100644 --- a/tests/OmniSharp.DotNetTest.Tests/LegacyGetTestStartInfoFacts.cs +++ b/tests/OmniSharp.DotNetTest.Tests/LegacyGetTestStartInfoFacts.cs @@ -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"); + } } } diff --git a/tests/OmniSharp.DotNetTest.Tests/LegacyRunTestFacts.cs b/tests/OmniSharp.DotNetTest.Tests/LegacyRunTestFacts.cs index 7984844761..bb3663352c 100644 --- a/tests/OmniSharp.DotNetTest.Tests/LegacyRunTestFacts.cs +++ b/tests/OmniSharp.DotNetTest.Tests/LegacyRunTestFacts.cs @@ -2,6 +2,7 @@ using Xunit; using Xunit.Abstractions; + namespace OmniSharp.DotNetTest.Tests { /// @@ -85,5 +86,37 @@ await RunDotNetTestAsync( testFramework: "nunit", shouldPass: true); } + + // These legacy tests currently do not work for MSTest based tests because + // for some reason in design mode, we end up returning results for all tests in a source. + //[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: false); + } } } diff --git a/tests/OmniSharp.DotNetTest.Tests/RunTestFacts.cs b/tests/OmniSharp.DotNetTest.Tests/RunTestFacts.cs index 01218d9884..14aa53faba 100644 --- a/tests/OmniSharp.DotNetTest.Tests/RunTestFacts.cs +++ b/tests/OmniSharp.DotNetTest.Tests/RunTestFacts.cs @@ -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); + } } } From 1d784839443541fbab35658e66e506dd0efe2d3e Mon Sep 17 00:00:00 2001 From: Abhitej Anoop John Bandi Date: Tue, 16 May 2017 21:37:56 +0530 Subject: [PATCH 3/3] Fixed up the Legacy tests flow to trim out the --wait-command which isn't required since we pass in the test list upfront. --- src/OmniSharp.DotNetTest/Legacy/LegacyTestManager.cs | 6 ++++-- .../OmniSharp.DotNetTest.Tests/LegacyRunTestFacts.cs | 12 +++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/OmniSharp.DotNetTest/Legacy/LegacyTestManager.cs b/src/OmniSharp.DotNetTest/Legacy/LegacyTestManager.cs index 248bc82bea..967ce0921c 100644 --- a/src/OmniSharp.DotNetTest/Legacy/LegacyTestManager.cs +++ b/src/OmniSharp.DotNetTest/Legacy/LegacyTestManager.cs @@ -67,7 +67,9 @@ public override RunTestResponse RunTest(string methodName, string testFrameworkN var testStartInfo = testStartInfoMessage.DeserializePayload(); 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) { @@ -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}"; diff --git a/tests/OmniSharp.DotNetTest.Tests/LegacyRunTestFacts.cs b/tests/OmniSharp.DotNetTest.Tests/LegacyRunTestFacts.cs index bb3663352c..9e13bf8cfb 100644 --- a/tests/OmniSharp.DotNetTest.Tests/LegacyRunTestFacts.cs +++ b/tests/OmniSharp.DotNetTest.Tests/LegacyRunTestFacts.cs @@ -86,10 +86,8 @@ await RunDotNetTestAsync( testFramework: "nunit", shouldPass: true); } - - // These legacy tests currently do not work for MSTest based tests because - // for some reason in design mode, we end up returning results for all tests in a source. - //[Fact] + + [Fact] public async Task RunMSTest() { await RunDotNetTestAsync( @@ -99,7 +97,7 @@ await RunDotNetTestAsync( shouldPass: true); } - //[Fact] + [Fact] public async Task RunMSTestDataDriveTest1() { await RunDotNetTestAsync( @@ -109,14 +107,14 @@ await RunDotNetTestAsync( shouldPass: false); } - //[Fact] + [Fact] public async Task RunMSTestDataDriveTest2() { await RunDotNetTestAsync( LegacyMSTestProject, methodName: "Main.Test.MainTest.DataDrivenTest2", testFramework: "mstest", - shouldPass: false); + shouldPass: true); } } }