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

Tests not executed if Console.WriteLine() is used #774

Closed
avendel opened this issue Jul 27, 2020 · 8 comments
Closed

Tests not executed if Console.WriteLine() is used #774

avendel opened this issue Jul 27, 2020 · 8 comments
Assignees
Milestone

Comments

@avendel
Copy link

avendel commented Jul 27, 2020

If the code path executed during a test contains a Console.WriteLine() without text content, the test will not execute. The following error is reported in the test output:

System.ArgumentException: The parameter cannot be null or empty.
Parameter name: message
   at Microsoft.VisualStudio.TestPlatform.Common.Logging.TestSessionMessageLogger.SendMessage(TestMessageLevel testMessageLevel, String message)
   at NUnit.VisualStudio.TestAdapter.NUnitEventListener.TestFinished(INUnitTestEventTestCase resultNode) in D:\repos\NUnit\nunit3-vs-adapter\src\NUnitTestAdapter\NUnitEventListener.cs:line 164
   at NUnit.VisualStudio.TestAdapter.NUnitEventListener.OnTestEvent(String report) in D:\repos\NUnit\nunit3-vs-adapter\src\NUnitTestAdapter\NUnitEventListener.cs:line 92

Here is code that reproduces this problem:

[TestFixture]
public class Tests {
    [Test]
    public void DoesNotWorkIn4alpha1() {
        Console.WriteLine();
        Assert.Pass();
    }

    [Test]
    public void Works() {
        Console.WriteLine("content");
        Assert.Pass();
    }
}

NUnit3TestAdapter 4.0.0-alpha.1
NUnit 3.12.0
Visual Studio Professional 2019 - 16.6.2
.Net Framework 4.8

This worked in NUnit3TestAdapter 3.15.1.

@OsirisTerje
Copy link
Member

Thanks for reporting! I would assume this will also fail in 3.17, and is related to the console outputting introduced there.

@avendel
Copy link
Author

avendel commented Jul 28, 2020

Yes, this also fails in 3.17, but not in 3.16.1. I should also clarify; tests do get executed, but their results aren't reported, which could lead to a developer missing a failing test.

image

@avendel
Copy link
Author

avendel commented Jul 28, 2020

This seems to have the same root cause as in #220 and #516:

        public void SendMessage(TestMessageLevel testMessageLevel, string message)
        {
            if (string.IsNullOrWhiteSpace(message))
            {
                throw new ArgumentException(ObjectModelCommonResources.CannotBeNullOrEmpty, "message");
            }

https://github.com/Microsoft/vstest/blob/master/src/Microsoft.TestPlatform.Common/Logging/TestSessionMessageLogger.cs#L65

@nico008
Copy link

nico008 commented Aug 3, 2020

I just faced the same problem, good to hear you are aware of this.

@OsirisTerje
Copy link
Member

Until fixed, the workaround is to set the ConsoleOut property in the runsettings to 0.

@OsirisTerje OsirisTerje added this to Todo in 4.0-alpha via automation Aug 26, 2020
@OsirisTerje OsirisTerje removed this from Todo in 4.0-alpha Aug 26, 2020
OsirisTerje added a commit that referenced this issue Sep 7, 2020
@OsirisTerje OsirisTerje added this to the 3.18 milestone Sep 7, 2020
@OsirisTerje OsirisTerje self-assigned this Sep 7, 2020
@OsirisTerje OsirisTerje modified the milestones: 3.18, 4.0.0-beta.1 Oct 28, 2020
FObermaier added a commit to NetTopologySuite/NetTopologySuite that referenced this issue Dec 11, 2020
@MisinformedDNA
Copy link

Looks like there was never a 3.18 release. Is that still planned?

@OsirisTerje
Copy link
Member

It is still planned, but the way forward is the 4.0.0. We expect 4.0.0 to not support legacy csproj with old package.configs, and it will not have a vsix either. 3.18 will try to cover as much as it can of the 4.0.0 features, but will still support the old legacy and will have a vsix. The release will follow the 4.0.0 release though.

@OsirisTerje
Copy link
Member

@MisinformedDNA Just to clarify the current state. 3.18 will not be released, 3.17 will be the latest in the 3.X series. The 4.X series do support legacy csproj with old packages.config, and will continue to do so as long as we are able to maintain it. The 4.X series will not have any VSIX.

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

No branches or pull requests

4 participants