Global SetUpFixture not running when using /fixture option.

1,011 views
Skip to first unread message

Ergwun

unread,
Aug 18, 2011, 8:43:34 PM8/18/11
to NUnit-Discuss
I have a SetUpFixture outside of any namespace, intended for setup
once at the start of any test runs.

This works fine if I am running all tests in the assembly (using the
console runner or GUI runner), or using the /run option with the
console runner to only run certain fixtures.

Since the GUI runner does not support specifying fixtures to run via
the /run option, I normally use the /fixture option, however this
option stops my global SetUpFixture from running.

How can I launch the GUI runner to run only certain fixtures and have
my global SetUpFixture run too?

Charlie Poole

unread,
Aug 18, 2011, 10:52:57 PM8/18/11
to nunit-...@googlegroups.com
Hi,

The /fixture option goes back to an earlier time, when folks would
completely set up the sequence of tests using it. As new features
have been added to NUnit, they generally didn't get applied to
to test suites (what we now call "legacy suites"). In fact, they didn't
even support TestFixtureSetUp originally, although they now do.

TestFixtureSetup is the answer to your problem. Put your setup
code in a [TestFixtureSetUp] method and the teardown into the
[TestFixtureTearDown] method. Depending on how your code
is written, you may be able to call the methods in your
SetUpFixture, or you may have to cut and paste it.

Charlie

> --
> You received this message because you are subscribed to the Google Groups "NUnit-Discuss" group.
> To post to this group, send email to nunit-...@googlegroups.com.
> To unsubscribe from this group, send email to nunit-discus...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nunit-discuss?hl=en.
>
>

Ergwun

unread,
Aug 19, 2011, 12:57:18 AM8/19/11
to NUnit-Discuss
Hi Charlie,

What I'm really looking for is a way to provide global setup that is
called once before executing any tests in any fixtures in an assembly.
That's how a [SetUpFixture] placed outside any namespace functions a
the moment, except when the /fixture option is used. I don't need the /
fixture option when using the console test runner, as I can specify
fixtures using the /run option, but I am stuck when using the GUI test
runner.

As I understand it, your recommendation of using [TestFixtureSetup]
would require the setup being added to each fixture, rather than once
globally. Please correct me if that is wrong.

The possible solutions I was hoping might exist would be either:
a) An equivalent to the console runner's /run=MyFixture option for the
GUI runner that doesn't stop a global [SetUpFixture] from working; or
b) An alternative to a global [SetUpFixture] that still works when
using the /fixture option.

Since it seems the /fixture option is approaching deprecation (and has
the negative side effect of negating a global SetUpFixture), it would
be nice if the /run option for the GUI runner worked the same way as
the console runner.

Thanks,
Geoff.

Charlie Poole

unread,
Aug 19, 2011, 1:28:36 AM8/19/11
to nunit-...@googlegroups.com
Hi Geoff

On Thu, Aug 18, 2011 at 9:57 PM, Ergwun <erg...@gmail.com> wrote:
> Hi Charlie,
>
> What I'm really looking for is a way to provide global setup that is
> called once before executing any tests in any fixtures in an assembly.
> That's how a [SetUpFixture] placed outside any namespace functions a
> the moment, except when the /fixture option is used. I don't need the /
> fixture option when using the console test runner, as I can specify
> fixtures using the /run option, but I am stuck when using the GUI test
> runner.
>
> As I understand it, your recommendation of using [TestFixtureSetup]
> would require the setup being added to each fixture, rather than once
> globally. Please correct me if that is wrong.

That's correct.

> The possible solutions I was hoping might exist would be either:
> a) An equivalent to the console runner's /run=MyFixture option for the
> GUI runner that doesn't stop a global [SetUpFixture] from working; or
> b) An alternative to a global [SetUpFixture] that still works when
> using the /fixture option.

Neither of those is available.

> Since it seems the /fixture option is approaching deprecation (and has
> the negative side effect of negating a global SetUpFixture), it would
> be nice if the /run option for the GUI runner worked the same way as
> the console runner.

Actually, it has been deprecated for a while, it's just that there's no
particular way to tell you that it's deprecated unless we issue a warning
from nunit-console. We may start doing that in 2.6.

For historical reasons, the /run option on the Gui doesn't take any
argument and simply executes all the tests that are loaded. We could
keep /run in it's current meaning and add /test (the new console option
replacing /run) to specify what is to be run.

Before doing that, I'd want to know whether there is much chance that
folks would use it, since it's more intended for batch execution than
for interactive use. The most likely outcome is that we'll find a way
to incorporate legacy suites or their future equivalent in the 3.0 gui.
You would then just click on them and execute.

For now, I'm afraid that the workaround I suggested is all that's
available. You can avoid coding it for every fixture separately by
use of a base class. However, it will still execute multiple times,
so you may want to use a flag to avoid re-running any code
that shouldn't be re-run.

Charlie

Ergwun

unread,
Aug 25, 2011, 7:52:34 PM8/25/11
to NUnit-Discuss
Hi Charlie,

Thanks for your reply and the workaround suggestions, which I am
using.

Since you say you may consider adding a /test option added to the GUI,
I would like to add my vote for it. Here's my use case:

I have a large test project with thousands of tests in it. To achieve
a poor man's Visual Studio integration, I make the project an
application which launches the NUnit Console runner, passing in the
executing assembly. This means I can just write some code or tests,
and hit F5 to run the tests. This allows me to easily debug tests,
setting breakpoints, double clicking tests etc.

To keep a nice quick code/test iteration, I normally only run the test
fixture for the part of the code base I am working on, and like to
have it run automatically without having to click in the GUI window.

I realise that there are a bunch of additional work-arounds my setup
will permit (e.g. have the test assembly's main method perform
additional global setup), but I want to keep things as simple as
possible so that the same code paths are executed whether running the
test executable directly, or loading it into an NUnit test runner.

Thanks,
Geoff.

Charlie Poole

unread,
Aug 25, 2011, 9:46:36 PM8/25/11
to nunit-...@googlegroups.com
If you keep the gui open, you only need to run the test fixture manually
once. Just set the options to re-load and re-run the tests whenever the
assembly is rebuilt.

Charlie

Reply all
Reply to author
Forward
0 new messages