Running a repeated test on multiple threads

268 views
Skip to first unread message

Ionut

unread,
Jun 4, 2010, 3:11:06 PM6/4/10
to NUnit-Discuss
Hi!
I am converting our testing assemblies from MbUnit to NUnit and I am
wondering if there is any similar attribute in NUnit to ThreadedRepeat
from MbUnit. I need to be able to run a test multiple times in
parallel and a suggestions about how this functionality can be
achieved is greatly appreciated.

Thank you!
Ionut

Simone Busoli

unread,
Jun 5, 2010, 6:32:01 AM6/5/10
to nunit-...@googlegroups.com
Hi Ionut, I don't think NUnit has this feature yet, you should file a feature request for NUnit here. Can you describe how it currecntly works in MbUnit or point to the documentation?

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


Ionut

unread,
Jun 6, 2010, 9:36:18 AM6/6/10
to NUnit-Discuss
Hi Simone,

I couldn't find the MbUnit documentation for the ThreadedRepeat
attribute, but there is a blog post that explains it:
http://darrell.mozingo.net/2008/05/30/mbunits-threadedrepeat-attribute/

The [ThreadedRepeat(5)] attribute will call the test 5 times in
parallel, firing off a separate thread for each one.

Is there an attribute with this functionality in NUnit or any way of
reproducing this functionality?

Thank you,
Ionut
On Jun 5, 5:32 am, Simone Busoli <simone.bus...@gmail.com> wrote:
> Hi Ionut, I don't think NUnit has this feature yet, you should file a
> feature request for NUnit here <https://bugs.launchpad.net/nunitv2>. Can you
> describe how it currecntly works in MbUnit or point to the documentation?
>  On Fri, Jun 4, 2010 at 21:11, Ionut <ionut.cior...@gmail.com> wrote:
>
> > Hi!
> > I am converting our testing assemblies from MbUnit to NUnit and I am
> > wondering if there is any similar attribute in NUnit to ThreadedRepeat
> > from MbUnit. I need to be able to run a test multiple times in
> > parallel and a suggestions about how this functionality can be
> > achieved is greatly appreciated.
>
> > Thank you!
> > Ionut
>
> > --
> > 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<nunit-discuss%2Bunsu...@googlegroups.com>
> > .

Simone Busoli

unread,
Jun 6, 2010, 9:47:30 AM6/6/10
to nunit-...@googlegroups.com
Hi Ionut, I don't think NUnit provides this functionality right now, but although I don't know the internals very well I think you might be have a working implementation in a few hours if you fiddle into NUnit's source code and figure out how other similar features are carried out (for instance, MaxTimeAttribute). In the meanwhile you can file a feature request.

To unsubscribe from this group, send email to nunit-discus...@googlegroups.com.

Sébastien Lorion

unread,
Jun 6, 2010, 12:10:23 PM6/6/10
to nunit-...@googlegroups.com
You might want to check what I have done to test a transaction handler
in my project on codeplex:

http://nlight.codeplex.com/SourceControl/changeset/view/45808#698639

Check the MultiThreadNestedContextTest method and related code, it
might be interesting to you.

Sébastien

> To unsubscribe from this group, send email to nunit-discus...@googlegroups.com.

Charlie Poole

unread,
Jun 6, 2010, 12:42:04 PM6/6/10
to nunit-...@googlegroups.com
Hi,

Definitely file a feature request, which will increase the probability of our adding this feature to some value greater than zero. :-)

For now, there is no way to do it. You could add both RequiresThread and Repeat attributes to the method, but the individual instances would still run sequentially, albeit on separate threads. 

You could, of course, either modify NUnit or spawn multiple instances of the test yourself, capturing all the results and passing them back to NUnit. This is non-trivial, however.

Charlie

Yann Duran

unread,
Jun 6, 2010, 10:24:40 PM6/6/10
to nunit-...@googlegroups.com
Hi Guys,

I'm trying to unit test a user control I've created, but I'm getting the
error listed below:

Test
'Luminous.Forms.v4._0.UnitTests.LuminousLayoutComboBoxTests.TopPanelHeight_New_ReturnsExpectedTopPanelHeight'
failed:
System.Exception : LayoutComboBox.New
----> System.Threading.ThreadStateException : Current thread must be set
to single thread apartment (STA) mode before OLE calls can be made. Ensure
that your Main function has STAThreadAttribute marked on it.
Controls\LuminousLayoutComboBox.vb(25,0): at
Luminous.Forms.LuminousLayoutComboBox..ctor()
Luminous.Forms.v4.0.UnitTests\LuminousLayoutComboBoxTests.vb(29,0): at
Luminous.Forms.v4._0.UnitTests.LuminousLayoutComboBoxTests.Setup()
--ThreadStateException
at System.Windows.Forms.ComboBox.set_AutoCompleteMode(AutoCompleteMode
value)
Controls\LuminousLayoutComboBox.Designer.vb(76,0): at
Luminous.Forms.LuminousLayoutComboBox.InitializeComponent()
Controls\LuminousLayoutComboBox.vb(18,0): at
Luminous.Forms.LuminousLayoutComboBox..ctor()

Not sure where I should actually put the STAThread attribute?

Thanks,

Yann

RJV

unread,
Jun 7, 2010, 1:58:29 AM6/7/10
to nunit-...@googlegroups.com
Hi Yann,
 
This is not related to NUnit. In .net, when you make a call to an unmanaged component, the apartment threads must be same. The STAThread attribute must be on the method that makes a call to your user control.
 
Jv

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




--
Regards,

Ravichandran Jv
http://ravichandranjv.blogspot.com

Yann Duran

unread,
Jun 7, 2010, 2:51:04 AM6/7/10
to nunit-...@googlegroups.com
Hi Jv,
 
The user control is actually working fine in the form I'm consuming it in, I only get this error when I'm unit testing it with NUnit. That's why I asked here.
 
Thanks,
 
Yann

RJV

unread,
Jun 7, 2010, 2:56:29 AM6/7/10
to nunit-...@googlegroups.com
Hi Yann,
 
In Tools->Settings, there is an option under Test Loader for Assembly Isolation. Can you check what is the option checked?
 
Jv

Yann Duran

unread,
Jun 7, 2010, 3:00:53 AM6/7/10
to nunit-...@googlegroups.com
Hi Jv,
 
Thanks for trying to help me with this. I'm actually using TestDriven.NET to drive the tests in the IDE itself, not in a separate NUnit instance. Does that make a difference to the problem, or where I should be asking the question?

RJV

unread,
Jun 7, 2010, 3:05:17 AM6/7/10
to nunit-...@googlegroups.com
Please check your Task Manager to see where the test is executing. Since it is a problem of apartment state, I guess it must be something related to process isolation.

Yann Duran

unread,
Jun 7, 2010, 3:07:27 AM6/7/10
to nunit-...@googlegroups.com
OK, thanks..

Kelly Anderson

unread,
Jun 7, 2010, 2:52:51 PM6/7/10
to nunit-...@googlegroups.com
A funny thing happened this morning. Independently of reading the list I tried to do the same thing myself, using RequiresThread... since it seemed like what I wanted to do.

        [Theory, RequiresThread]
        public void EverythingWorksOutInTheEnd(string url)
        {
             ...
        }

As you have said, this doesn't work in that the threads are invoked sequentially. This is very sad for me, so I would also vote to add this feature. It kind of goes along with what I've been saying recently about testing multiple threaded applications using Theory. It would be very useful.

For now, I will take your advise and implement the multiple threading testing on my own, but then (sadly) I don't get to use the fun Theory mechanisms to scramble the parameters.

-Kelly

Yann Duran

unread,
Jun 8, 2010, 1:03:07 AM6/8/10
to nunit-...@googlegroups.com
Just in case anyone else runs across this problem, I found an answer here: http://frater.wordpress.com/2008/09/08/nunit-and-stathread/
 
Adding the following to an app.config file for the dll containing the tests worked (ie the tests that were failing, now passed):
 
<configSections>
<sectionGroup name="NUnit">
<section name="TestRunner" type="System.Configuration.NameValueSectionHandler"/>
</sectionGroup>
</configSections>

<NUnit>
<TestRunner>
<add key="ApartmentState" value="STA" />
</TestRunner>
</NUnit>

Charlie Poole

unread,
Jun 8, 2010, 5:55:00 AM6/8/10
to nunit-...@googlegroups.com
This will solve the problem but could cause others in some instances because now _all_ tests are run using the STA. A cleaner approach is to use the RequiresSTA attribute on the method or fixture that needs it.

Charlie

Yann Duran

unread,
Jun 8, 2010, 9:17:20 PM6/8/10
to nunit-...@googlegroups.com
Ahh, thanks for that Charlie. I'm much happier with your proposed solution.
 
Yann
Reply all
Reply to author
Forward
0 new messages