nunit3-vs-adapter: No output or errors from nunit tests - 1.10.0-beta2

This issue is moved from the OmniSharp repository, 1.10.0-beta2 refers to the C# extension for Visual Studio Code which also uses the adapter.

From @tomzo on May 14, 2017 9:54

Environment data

dotnet --info output:

.NET Command Line Tools (1.0.4)

Product Information:
 Version:            1.0.4
 Commit SHA-1 hash:  af1e6684fd

Runtime Environment:
 OS Name:     debian
 OS Version:  8
 OS Platform: Linux
 RID:         debian.8-x64
 Base Path:   /usr/share/dotnet/sdk/1.0.4

VS Code version: C# Extension version: 1.12.1

omnisharp-vscode: 1.10.0-beta2

Steps to reproduce

Here is a repo which exactly reproduces this https://github.com/tomzo/bug-nunit-no-output-vscode

Just run

dotnet restore
dotnet test DefaultTests/DefaultTests.csproj

Then try the same in vscode by clicking on run test on one of the tests.

Expected behavior

There are tests which are failingand there is standard output printed in one of the tests.

[Test]
        public void Test1()
        {
			new Class1 ();
            Console.WriteLine("Test body running..");
        }

		[Test]
        public void Test2()
        {
            Assert.AreEqual(2,26);
        }

I would expect to see both the stdout and especially failed asserts from nunit test cases.

Actual behavior

In VsCode .NET Test Log output just counts the failed tests

NUnit Adapter 3.8.0.0: Test discovery starting
NUnit Adapter 3.8.0.0: Test discovery complete
NUnit Adapter 3.8.0.0: Test execution started
Running selected tests in /ide/work/nunit-repro/DefaultTests/bin/Debug/netcoreapp1.0/DefaultTests.dll
NUnit3TestExecutor converted 2 of 2 NUnit test cases
NUnit Adapter 3.8.0.0: Test execution complete

Total tests: 1. Passed: 0. Failed: 1. Skipped: 0

The output when running with dotnet is fine:

$ dotnet test  DefaultTests/DefaultTests.csproj 
Build started, please wait...
/usr/share/dotnet/sdk/1.0.4/Sdks/Microsoft.NET.Sdk/Sdk/Sdk.targets(40,3): warning MSB4011: "/usr/share/dotnet/sdk/1.0.4/Microsoft.CSharp.targets" cannot be imported again. It was already imported at "/ide/work/nunit-repro/ExampleLib/ExampleLib.csproj (28,3)". This is most likely a build authoring error. This subsequent import will be ignored. 
Build completed.

Test run for /ide/work/nunit-repro/DefaultTests/bin/Debug/netcoreapp1.0/DefaultTests.dll(.NETCoreApp,Version=v1.0)
Microsoft (R) Test Execution Command Line Tool Version 15.0.0.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
NUnit Adapter 3.8.0.0: Test execution started
Running all tests in /ide/work/nunit-repro/DefaultTests/bin/Debug/netcoreapp1.0/DefaultTests.dll
NUnit3TestExecutor converted 2 of 2 NUnit test cases
NUnit Adapter 3.8.0.0: Test execution complete
Failed   Test2
Error Message:
   Expected: 2
  But was:  26

Stack Trace:
at DefaultTests.UnitTest1.Test2() in /ide/work/nunit-repro/DefaultTests/UnitTest1.cs:line 20


Total tests: 2. Passed: 1. Failed: 1. Skipped: 0.
Test Run Failed.
Test execution time: 1.8351 Seconds

Copied from original issue: OmniSharp/omnisharp-vscode#1480

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 38 (32 by maintainers)

Most upvoted comments

Here’s where we do it… from TestConverter.cs…

                string message = node?.SelectSingleNode("message")?.InnerText;
                // If we're running in the IDE, remove any caret line from the message
                // since it will be displayed using a variable font and won't make sense.
                if (!string.IsNullOrEmpty(message) && NUnitTestAdapter.IsRunningUnderIDE)
                {
                    string pattern = NL + "  -*\\^" + NL;
                    message = Regex.Replace(message, pattern, NL, RegexOptions.Multiline);
                }

IsRunningUnderIDE is true when the entry program is “vstest.executionengine”, “vstest.discoveryengine” or “TE.ProcessHost”.

Should be easy enough to check by creating a failing equal assert and seeing if the error message includes the caret line.