msbuildtasks icon indicating copy to clipboard operation
msbuildtasks copied to clipboard

NUnit task reporting failures incorrectly due to console output?

Open rsbarro opened this issue 11 years ago • 1 comments

Hello,

I think I may have found a bug in the NUnit task. Here's what I'm seeing:

I have a test class that writes some output to the console:

using System;
using NUnit.Framework;

namespace NUnitTester
{
    [TestFixture]
    public class ConsoleTester
    {
        [Test]
        public void Test_Writing_ERROR_To_Console()
        {
            Console.WriteLine("ERROR: output with the word 'ERROR:' happened.");
            Assert.AreEqual(0, 0);
        }

        [Test]
        public void Test_Writing_Error_To_Console()
        {
            Console.WriteLine("Error: output with the word 'Error:' happened.");
            Assert.AreEqual(0, 0);
        }

        [Test]
        public void Test_Writing_SpaceError_To_Console()
        {
            Console.WriteLine(" Error: output with the word ' Error:' happened.");
            Assert.AreEqual(0, 0);
        }

        [Test]
        public void Test_Writing_DashError_To_Console()
        {
            //This test works ok
            Console.WriteLine("-Error: output with the word '-Error:' happened.");
            Assert.AreEqual(0, 0);
        }
    }
}

When I execute this test using nunit-console.exe (ver 2.6.4), all tests pass, as expected.

However, when I use msbuild to execute the following script to build the solution and execute the tests, the build fails, ostensibly because of the various "error" strings written to the console.

<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
  <Import Project="$(MSBuildExtensionsPath)\ExtensionPack\4.0\MSBuild.ExtensionPack.VersionNumber.targets" />
  <Import Project="$(MSBuildExtensionsPath)\ExtensionPack\4.0\MSBuild.ExtensionPack.tasks" />

  <!-- Define properties -->
  <PropertyGroup>
    <CodeRoot>C:\Testbed\</CodeRoot>
    <SolutionRoot>C:\Testbed\NUnitTester\</SolutionRoot>
  </PropertyGroup>

  <!-- Build using .sln file -->
  <Target Name="Build">
    <Message Text="Building NUnitTester.sln" />
    <MSBuild Projects="$(SolutionRoot)\NUnitTester.sln" Targets="Clean;Rebuild" Properties="Platform=Any CPU" />
  </Target>

  <!-- Run Unit Tests -->
  <Target Name="Test" DependsOnTargets="Build">
    <NUnit
          Assemblies="$(SolutionRoot)\bin\Debug\NUnitTester.dll"
          ContinueOnError="false"
          OutputXmlFile="NUnitTester-results.xml"
          ToolPath="C:\Program Files (x86)\NUnit 2.6.4\bin\"
          ShowLabels="true"
        />
  </Target>

</Project>

Is this a bug with the NUnit task, or do I have something configured incorrectly?

Thanks, Rich

rsbarro avatar Jan 05 '15 20:01 rsbarro

Having exactly the same problem here! In our case we launch the nunit-console.exe (ver 2.6.2) through a MSBuild task, through a Jenkins job. The version of MSBuild engine is 4.0.30319.1 It also appears with MSBuild engine is 4.0.30319.18408

This problem does NOT appear if Build Engine is version 4.0.30319.17929 Nor even with Build Engine version 4.6.1055.0

guillaumeagile avatar Jan 29 '16 09:01 guillaumeagile