Help understanding test and fixture setup/teardown differences between NUnit 2.6.4 and NUnit 3.0.0

446 views
Skip to first unread message

Mike Long

unread,
Oct 13, 2015, 10:43:45 PM10/13/15
to NUnit-Discuss
I am quite new to unit testing frameworks and C# programming. I have been trying to get my head wrapped around test and test fixture setup/teardown behaviour and parallel test running.  While doing so I have setup a very basic test assembly project using Visual Studio 2013 and used the package manager to install the Nunit 2.6.4 core and runners as well as the VS test adapter 2.0.0. My test fixture class looks like:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using NUnit.Framework;

namespace Sandbox
{
    [TestFixture]
    public class Test
    {
        [TestFixtureSetUp]
        public void SetupFixture()
        {
            Console.WriteLine("\n*** In Test Fixture Setup");            
        }

        [TestFixtureTearDown]
        public void TeardownFixture()
        {
            Console.WriteLine("\n*** In Test Fixture TearDown\n");
        }

        [SetUp]
        public void SetupTest()
        {
            Console.WriteLine("\n*** In Test Setup");
        }

        [TearDown]
        public void TearDownTest()
        {
            Console.WriteLine("\n*** In Test TearDown");
        }

        [Test]
        public void Area51()
        {
            Console.WriteLine("\n*** In Test Area51");
        }

        [Test]
        public void Area52()
        {
            Console.WriteLine("\n*** In Test Area52");
        }
    }
}

When I run the tests in the assembly via the VS adapter or nunit-console.exe I receive the expected Console.WriteLine output in the VS output window and console window respectively. If I use the Nuget package manager to remove the Nunit 2.6.4 and VS Adapter 2.0.0 from the project and install the Nunit 3.0 Beta and VS Adapter 3.0 I cannot see any of the Console.WriteLine output in the VS output window and only see the test setup, test, and test teardown output when using nunit-console.exe (I did update the TestFixtureSetup and TestFixtureTeardown attributes to be OneTimeSetup and OneTimeTearDown respectively after upgrading to NUnit 3.0)

I have tried going through the NUnit 3.0 documentation provided at https://github.com/nunit/nunit/wiki but I suspect that my limited programming experience may be preventing me from comprehending something would help me understand why I am not seeing the expected setup/test/teardown console output. I have also attached the console and VS output window output from the 2.6.4 and 3.0.0 test runs to this post.

thank you much for any help offered,
Mike Long
nunit_vs_adapter_2.0.txt
nunit_vs_adapter_3.0.2.txt
nunit_console_2.6.4.14350.txt
nunit_console_3.0.5715.txt

Charlie Poole

unread,
Oct 13, 2015, 11:53:42 PM10/13/15
to NUnit-Discuss
The NUnit 3 adapter is attaching console output associated with a
result to that result - that is to the VS TestResult that is sent to
Visual Studio. It should appear when you click on the test case to
display the result.

Console output from the SetUp and Teardown should appear in the same
place, since they are associated with a test.

Output from OneTimeSetUp and OneTimeTearDown probably won't appear,
since the TestExplorer only deals with test cases.

Charlie
> --
> You received this message because you are subscribed to the Google Groups
> "NUnit-Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to nunit-discus...@googlegroups.com.
> To post to this group, send email to nunit-...@googlegroups.com.
> Visit this group at http://groups.google.com/group/nunit-discuss.
> For more options, visit https://groups.google.com/d/optout.

Mike Long

unread,
Oct 14, 2015, 11:49:26 AM10/14/15
to NUnit-Discuss
Thank you for your time and feedback Charlie. The test, test setup and test teardown output under NUnit 3.0 can be found in the output provided in the VS Test Explorer result view as well as in the console runner output  as you have described. I started running through this exercise because I have some TestFixtureSetup code I was using under NUnit 2.6.4 to start up an IIS Express instance, that fails to start the IIS Express process in the OneTimeSetup after upgrading to NUnit 3.0. I haven't been able to capture any of the output from the IIS Express process startup failure to get a handle on why. I will investigate this a little further and post a separate question for it as you have answered this one clearly and I don't want to morph the original intent of the post.
Reply all
Reply to author
Forward
0 new messages