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

No stdout capture when running in Visual Studio as MS runner does #242

Closed
kkm000 opened this issue Dec 21, 2014 · 2 comments
Closed

No stdout capture when running in Visual Studio as MS runner does #242

kkm000 opened this issue Dec 21, 2014 · 2 comments

Comments

@kkm000
Copy link

kkm000 commented Dec 21, 2014

This may be related to #173 but I am not qualified to understand that issue.

When a test writes to stdout, VS own test runner captures output into the test report, and makes it available in Test Explorer under the Output link. xUnit runner does not do that.

This is essential in test development, since some values need to be printed to be compared against. In my particular case, I am testing a compiler and much match its expected error messages. Of course I can see them by breaking into a debugger while running tests, but that has become a major hassle since I switched to xUnit.

Sample code:

using System;
using MS=Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;

public class BlueprintSyntax
{
    [Fact]
    public void XUnitFact() {
        Console.WriteLine("xUnit output");
    }
};

[MS.TestClass]
public class Sample
{
    [MS.TestMethod]
    public void MSTestCase() {
        Console.WriteLine("MS output");
    }
};

1
2

@bradwilson
Copy link
Member

Sorry, we do not capture standard output in v2.

The design of xUnit.net v2 makes such designs impossible. The Console is a shared resource, and writing to that Console contains no context information in which to relate the written text back to the writer. Since many unit tests are running in parallel, it is therefore impossible to relate the written text back to the unit test in question.

We did support this in v1, because we didn't support parallelization. MSTest similarly supports this because they do not support parallelization.

Our alternative is ITestOutputHelper, which you can accept as a constructor argument for your unit test. An example of the usage can be found here:

class ClassUnderTest : IDisposable

(We don't have an example/documentation for this yet, so the only usage I can point you to is in our unit test suite.)

@kkm000
Copy link
Author

kkm000 commented Dec 22, 2014

That's a viable alternative, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants