[OneTimeSetup} runs after [Test] and I can not figure out why!! Please Help

71 views
Skip to first unread message

gvsamu...@gmail.com

unread,
Apr 14, 2017, 6:25:41 PM4/14/17
to NUnit-Discuss
Example:

namespace ServerTest
{
[TestFixture]
public class ServerTest
{

       [OneTimeSetup]
        public void setup()
{
Print("Setup");
       }

[Test]
public void Test1()
{
Print("Test1");
       }
}

Using Jenkins to call nunit3-console.exe to run my dll
Looks like this:
C:\Tools\nunit\nunit3-console.exe C:\Tests\ServerTest.dll 

When I run the test, the print out looks like this:

Test1
Setup

I upgrade from 2.5.8 nunit.framework which used [TestFixtureSetUp] instead of [OneTimeSetup] and it worked correctly.
When I switched to 3.6.1 nunit.framework which I converted it to use [OneTimeSetup] instead, the ordering became wrong. I'm not sure why!
What am I doing wrong? Can't figure it out.


Charlie Poole

unread,
Apr 14, 2017, 6:27:41 PM4/14/17
to NUnit-Discuss
You are using your own Print method. What is in it?
> --
> 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 https://groups.google.com/group/nunit-discuss.
> For more options, visit https://groups.google.com/d/optout.

Charlie Poole

unread,
Apr 14, 2017, 6:35:24 PM4/14/17
to NUnit-Discuss
Assuming you are using Console.WriteLine to output the lines...

NUnit 3 groups all output with the test result. Of course, the test
result is not available until after the test is finished. Your Test1
naturally finishes before the containing fixture finishes, so the
order of display is reversed.

If you want to see output at the time it is produced, NUnit 3.6.1 also
supports "immediate" output, appears right away, without waiting for
the test to end.

"Normal" (end of test) output is produced by:
* Console.Write(Line)
* TestContext.Write(Line)

Immediate output is produced by:
* Console.Error.Write(Line)
* TestContext.Error.Write(Line)
* TestContext.Progress.Write(Line)
Reply all
Reply to author
Forward
0 new messages