query selected categories?

33 views
Skip to first unread message

Schnick, Michael

unread,
Dec 16, 2010, 11:51:09 AM12/16/10
to nunit-...@googlegroups.com

Hi,

 

in our tests, we sometimes just want to run a subset of our tests.

Some of the tests should not be run at all, some other tests should only be run on a smaller set of files (found in a directory).

Right now, we’re using a mixture of both categories and a configuration setting in app.config.

 

It would ease our lives a little if we could query which categories have been selected prior to running a test.

Does Nunit expose this information?

 

Thanks

 

Michael Schnick

 

Michael Schnick, Cognex Ltd, Germany

Charlie Poole

unread,
Dec 16, 2010, 12:49:34 PM12/16/10
to nunit-...@googlegroups.com
Currently, there's no feature like that. If you would like to request it,
please be sure to include an example of how it might work.

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.
>

Yann Duran

unread,
Dec 16, 2010, 6:48:05 PM12/16/10
to nunit-...@googlegroups.com
Hi Michael,
 
I don't know if this will be of any help to you, but the way I handle the situation you describe is with TestDriven.NET. I don't run the NUnit GUI any more, with TestDriven I can right-click a single test project to run just the tests in that project, or I can right-click the solution to run all the tests in the whole solution (no matter how many test projects are contained in it), or I can even right click inside a single test class to run just the tests in that class, or even right-click inside a single test to run just that test.
 
I can't even begin to imagine doing it the old way with the GUI any more. Charlie may well inform me that what I'm doing in possible in the NUnit GUI also, but I like the ability to do it all from within VS, not having to keep going to another program to run my tests.
 
Sure, I don't get the red/green stuff this way, but I get much finer granularity over what tests I can run at any particular time.
 
TestDriven.NET ROCKS! Smile emoticon (So does NUnit too of course, lol)
 
Yann
--
Emoticon1.gif

Charlie Poole

unread,
Dec 16, 2010, 7:23:31 PM12/16/10
to nunit-...@googlegroups.com
Hi Yann,

I guess I assumed that Michael wanted to do this in the course of a batch run,
which is really where categories are most useful.

And yes, you could do the same in the NUnit gui by selecting individual tests
to run. That's not as convenient as clicking the test method IFF you already
have its code open. Do you find you have the code open for the tests you
want to run most of the time?

Charlie

Yann Duran

unread,
Dec 17, 2010, 12:11:43 AM12/17/10
to nunit-...@googlegroups.com
Hi Charlie,
 
Ahh, I hadn't considered batch runs.
 
Yes, I'm usually working on the code I'm wanting to test (trying to TDD, but not always succeeding, lol), so I may want to run just that one test, or the tests in the test class to see if I broke anything, or occasionally (or at the beginning/end of the day) I run the whole solution's tests.
 
I organise my tests into a class per SUT & a test project per code project.
 
Yann

Schnick, Michael

unread,
Dec 17, 2010, 3:36:04 AM12/17/10
to nunit-...@googlegroups.com
Hi Charlie,

thanks for the prompt feedback.

What I'd like to do is in fact using batch runs.
Either with a batch run or with the NUnit GUI, I'd like to include categories and the run the tests.

For us, it would be enough to get the list of selected categories exposed through a list or an Array, just like
String [] NUnit.SelectedCategories(), listing all the categories as single items that have been included.

Do you think this is feasible?

-Michael

-----Original Message-----
From: nunit-...@googlegroups.com [mailto:nunit-...@googlegroups.com] On Behalf Of Charlie Poole
Sent: Donnerstag, 16. Dezember 2010 18:50
To: nunit-...@googlegroups.com
Subject: Re: [nunit-discuss] query selected categories?

Charlie Poole

unread,
Dec 17, 2010, 10:48:35 AM12/17/10
to nunit-...@googlegroups.com
Hi Michael,

Yes it's feasible. The currently selected categories could be made
available as a
part of the TestContext - for example, TestContext.SelectedCategories.

To understand and prioritize this better, can you explain a bit more how you
would use it? I'm still not completely understanding what you want to do
with it. Maybe a bit of pseudocode would help...

Charlie

On Fri, Dec 17, 2010 at 12:36 AM, Schnick, Michael

Schnick, Michael

unread,
Dec 20, 2010, 4:36:20 AM12/20/10
to nunit-...@googlegroups.com
Hi Charlie,

this sounds great.

Here's what I'd do:

[Test]
[Category("long")]
[Category("short")]
Public void SomeTest()
{
List.Add(item1);
List.Add(item2);
If(TestContext.SelectedCategories.Contains("long"))
{
List.Add(item3);
List.Add(item4);
...
List.Add(itemN);
}
ProcessList(List);
}

Depending on the content of the list, this test might either take an hour (full scope) or 2 minutes (reduced scope).

So, for our short tests where the results need to be available ASAP, we'd like to make sure that we're using the correct number of items here.

Thanks

Charlie Poole

unread,
Dec 20, 2010, 10:37:06 AM12/20/10
to nunit-...@googlegroups.com
Hi Michael,

Please make a feature request for this at http://bugs.launchpad.net/nunitv2
so we can track it for 2.6.

Charlie

On Mon, Dec 20, 2010 at 1:36 AM, Schnick, Michael

Reply all
Reply to author
Forward
0 new messages