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

Return the stdout messages to improve test logging #1203

Merged
merged 7 commits into from
May 29, 2018
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
4 changes: 3 additions & 1 deletion src/OmniSharp.DotNetTest/Models/DotNetTestResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ public class DotNetTestResult
public string Outcome { get; set; }
public string ErrorMessage { get; set; }
public string ErrorStackTrace { get; set; }
public string[] StandardOutput { get; set; }
public string[] StandardError { get; set; }
}
}
}
7 changes: 6 additions & 1 deletion src/OmniSharp.DotNetTest/VSTestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,12 @@ public override RunTestResponse RunTest(string[] methodNames, string testFramewo
MethodName = testResult.TestCase.FullyQualifiedName,
Outcome = testResult.Outcome.ToString().ToLowerInvariant(),
ErrorMessage = testResult.ErrorMessage,
ErrorStackTrace = testResult.ErrorStackTrace
ErrorStackTrace = testResult.ErrorStackTrace,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to unit test this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

StandardOutput = testResult.Messages
.Where(message => message.Category == TestResultMessage.StandardOutCategory)
.Select(message => message.Text).ToArray(),
StandardError = testResult.Messages.Where(message => message.Category == TestResultMessage.StandardErrorCategory)
.Select(message => message.Text).ToArray()
});

return new RunTestResponse
Expand Down
15 changes: 15 additions & 0 deletions test-assets/test-projects/MSTestProject/TestProgram.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Main.Test
Expand Down Expand Up @@ -27,6 +28,20 @@ public void DataDrivenTest2(int i)
Assert.IsTrue(i >= 0);
}

[TestMethod]
public void FailingTest()
{
Assert.AreEqual(1, 2);
}

[TestMethod]
public void CheckStandardOutput()
{
int a = 1, b = 1;
Console.WriteLine($"a = {a}, b = {b}");
Assert.AreEqual(a,b);
}

private void UtilityFunction()
{

Expand Down
15 changes: 15 additions & 0 deletions test-assets/test-projects/NUnitTestProject/TestProgram.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
using System;

namespace Main.Test
{
Expand Down Expand Up @@ -30,6 +31,20 @@ public void SourceDataDrivenTest(int i)
Assert.True(i > 0);
}

[Test]
public void FailingTest()
{
Assert.AreEqual(1, 2);
}

[Test]
public void CheckStandardOutput()
{
int a = 1, b = 1;
Console.WriteLine($"a = {a}, b = {b}");
Assert.AreEqual(a,b);
}

public void UtilityFunction()
{

Expand Down
23 changes: 19 additions & 4 deletions test-assets/test-projects/XunitTestProject/TestProgram.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Xunit;

namespace Main.Test
Expand All @@ -9,26 +10,26 @@ public void Test()
{
Assert.True(true);
}

[Theory]
[InlineData(0)]
[InlineData(1)]
public void DataDrivenTest1(int i)
{
Assert.True(i > 0);
}

[Theory]
[InlineData(0)]
[InlineData(1)]
public void DataDrivenTest2(int i)
{
Assert.True(i >= 0);
}

private void UtilityFunction()
{

}

[Fact(DisplayName = "My Test Name")]
Expand All @@ -48,5 +49,19 @@ public void TestWithSimilarNameFooBar()
{
Assert.True(true);
}

[Fact]
public void FailingTest()
{
Assert.Equal(1, 2);
}

[Fact]
public void CheckStandardOutput()
{
int a = 1, b = 1;
Console.WriteLine($"a = {a}, b = {b}");
Assert.Equal(a,b);
}
}
}
81 changes: 81 additions & 0 deletions tests/OmniSharp.DotNetTest.Tests/RunTestFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,33 @@ public async Task RunXunitTestWithSimilarName()
Assert.Single(response.Results);
}

[Fact]
public async Task RunXunitFailingTest()
{
var response = await RunDotNetTestAsync(
XunitTestProject,
methodName: "Main.Test.MainTest.FailingTest",
testFramework: "xunit",
shouldPass: false);

Assert.Single(response.Results);
Assert.NotEmpty(response.Results[0].ErrorMessage);
Assert.NotEmpty(response.Results[0].ErrorStackTrace);
}

[Fact]
public async Task RunXunitStandardOutputIsReturned()
{
var response = await RunDotNetTestAsync(
NUnitTestProject,
methodName: "Main.Test.MainTest.CheckStandardOutput",
testFramework: "xunit",
shouldPass: true);

Assert.Single(response.Results);
Assert.NotEmpty(response.Results[0].StandardOutput);
}

[Fact]
public async Task RunNunitTest()
{
Expand Down Expand Up @@ -106,6 +133,33 @@ await RunDotNetTestAsync(
shouldPass: true);
}

[Fact]
public async Task RunNunitFailingTest()
{
var response = await RunDotNetTestAsync(
NUnitTestProject,
methodName: "Main.Test.MainTest.FailingTest",
testFramework: "nunit",
shouldPass: false);

Assert.Single(response.Results);
Assert.NotEmpty(response.Results[0].ErrorMessage);
Assert.NotEmpty(response.Results[0].ErrorStackTrace);
}

[Fact]
public async Task RunNunitStandardOutputIsReturned()
{
var response = await RunDotNetTestAsync(
NUnitTestProject,
methodName: "Main.Test.MainTest.CheckStandardOutput",
testFramework: "nunit",
shouldPass: true);

Assert.Single(response.Results);
Assert.NotEmpty(response.Results[0].StandardOutput);
}

[Fact]
public async Task RunMSTestTest()
{
Expand Down Expand Up @@ -135,5 +189,32 @@ await RunDotNetTestAsync(
testFramework: "mstest",
shouldPass: true);
}

[Fact]
public async Task RunMSTestFailingTest()
{
var response = await RunDotNetTestAsync(
MSTestProject,
methodName: "Main.Test.MainTest.FailingTest",
testFramework: "mstest",
shouldPass: false);

Assert.Single(response.Results);
Assert.NotEmpty(response.Results[0].ErrorMessage);
Assert.NotEmpty(response.Results[0].ErrorStackTrace);
}

[Fact]
public async Task RunMSTestStandardOutputIsReturned()
{
var response = await RunDotNetTestAsync(
MSTestProject,
methodName: "Main.Test.MainTest.CheckStandardOutput",
testFramework: "mstest",
shouldPass: true);

Assert.Single(response.Results);
Assert.NotEmpty(response.Results[0].StandardOutput);
}
}
}
21 changes: 12 additions & 9 deletions tests/OmniSharp.DotNetTest.Tests/TestDiscoveryFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ public TestDiscoveryFacts(ITestOutputHelper output)
}

[Theory]
[InlineData("XunitTestProject", "TestProgram.cs", 7, 20, true, "XunitTestMethod", "Main.Test.MainTest.Test")]
[InlineData("XunitTestProject", "TestProgram.cs", 15, 20, true, "XunitTestMethod", "Main.Test.MainTest.DataDrivenTest1")]
[InlineData("XunitTestProject", "TestProgram.cs", 23, 20, true, "XunitTestMethod", "Main.Test.MainTest.DataDrivenTest2")]
[InlineData("XunitTestProject", "TestProgram.cs", 28, 21, false, "", "")]
[InlineData("NUnitTestProject", "TestProgram.cs", 7, 20, true, "NUnitTestMethod", "Main.Test.MainTest.Test")]
[InlineData("NUnitTestProject", "TestProgram.cs", 14, 20, true, "NUnitTestMethod", "Main.Test.MainTest.DataDrivenTest1")]
[InlineData("NUnitTestProject", "TestProgram.cs", 21, 20, true, "NUnitTestMethod", "Main.Test.MainTest.DataDrivenTest2")]
[InlineData("NUnitTestProject", "TestProgram.cs", 27, 20, true, "NUnitTestMethod", "Main.Test.MainTest.SourceDataDrivenTest")]
[InlineData("NUnitTestProject", "TestProgram.cs", 32, 20, false, "", "")]
[InlineData("XunitTestProject", "TestProgram.cs", 8, 20, true, "XunitTestMethod", "Main.Test.MainTest.Test")]
[InlineData("XunitTestProject", "TestProgram.cs", 16, 20, true, "XunitTestMethod", "Main.Test.MainTest.DataDrivenTest1")]
[InlineData("XunitTestProject", "TestProgram.cs", 24, 20, true, "XunitTestMethod", "Main.Test.MainTest.DataDrivenTest2")]
[InlineData("XunitTestProject", "TestProgram.cs", 53, 20, true, "XunitTestMethod", "Main.Test.MainTest.FailingTest")]
[InlineData("XunitTestProject", "TestProgram.cs", 59, 20, true, "XunitTestMethod", "Main.Test.MainTest.CheckStandardOutput")]
[InlineData("XunitTestProject", "TestProgram.cs", 29, 21, false, "", "")]
[InlineData("NUnitTestProject", "TestProgram.cs", 8, 20, true, "NUnitTestMethod", "Main.Test.MainTest.Test")]
[InlineData("NUnitTestProject", "TestProgram.cs", 15, 20, true, "NUnitTestMethod", "Main.Test.MainTest.DataDrivenTest1")]
[InlineData("NUnitTestProject", "TestProgram.cs", 22, 20, true, "NUnitTestMethod", "Main.Test.MainTest.DataDrivenTest2")]
[InlineData("NUnitTestProject", "TestProgram.cs", 28, 20, true, "NUnitTestMethod", "Main.Test.MainTest.SourceDataDrivenTest")]
[InlineData("NUnitTestProject", "TestProgram.cs", 34, 20, true, "NUnitTestMethod", "Main.Test.MainTest.FailingTest")]
[InlineData("NUnitTestProject", "TestProgram.cs", 47, 20, false, "", "")]
public async Task FindTestMethods(string projectName, string fileName, int line, int column, bool found, string expectedFeatureName, string expectedMethodName)
{
using (var testProject = await this._testAssets.GetTestProjectAsync(projectName))
Expand Down