Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6061305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:55:23+00:00 2026-05-23T08:55:23+00:00

Is nunit applicable in multithreading context. I do not want nunit to test my

  • 0

Is nunit applicable in multithreading context.
I do not want nunit to test my multithreading application of course, but want to use nunit assertions

Simple example – this test is “green”. What do I wrong?

[Test]
public void Test()
{
  Action action = Async;
  action.BeginInvoke(action.EndInvoke, null).AsyncWaitHandle.WaitOne();
}

private void Async()
{
  Assert.IsTrue(false);
  Assert.DoesNotThrow( () =>
                       {
                         Console.WriteLine("Async");
                         throw new InvalidOperationException();
                       });
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:55:23+00:00Added an answer on May 23, 2026 at 8:55 am

    The NUnit test runner executable is configured to ignore exceptions on non-test threads. You can configure this behaviour via app.config configuration element:

    legacyUnhandledExceptionPolicy

    You can configure non-test threads to cause unhandled exceptions, and so tests will then fail. The caveat is that non-test thread exceptions may be raised whilst another test is running so you may not get an accurate picture of which test failed. Also, as this will be an unhandled exception, test execution will stop at the point the exception happens, rather then continue which is the normal behaviour.

    Better than ignoring though in my opinion.

    The following article goes into some detail on the topic for the ReSharper test runner, but the principles are the same.

    ReSharper test runner – hidden thread exceptions

    If you do have multi-threading aspects, from an assertion point of view, I find it better to set flags etc on the non-test thread, wait for the non-test thread to finish, and then assert the state on the test thread. In this way assertion exceptions are raised on the main thread and tests run as expected.

    Contrived Example

        [Test]
        public void Test()
        {
            Exception ex = null;
    
            Action test = () =>
            {
                Console.WriteLine("Async");
    
                ex = new InvalidOperationException();
            };
    
            test.BeginInvoke(test.EndInvoke, null).AsyncWaitHandle.WaitOne();
    
            Assert.That(ex, Is.Null, "Exception did not happen.");
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use NUNIT and mostly Test with ValueSource to do assertions. But i never
I've used NUnit before, but not in a while, and never on this machine.
we use the nunit.exe application to run our (integration)test Now i experience the problem
Some of NUnit 's Assert methods are overloaded to use ICollection but not ICollection<T>
Using nUnit to test the output (currency formatting) for a specific culture but we
Using Nunit, I want to be able to write a test fixture that will
I'm using NUnit (but have also tried this with VS testing) and I'm having
I usually use Nunit but in my current project I am using MSTest. Now
Using NUnit 2.5 in VS 2008, i'm not sure how to test that a
I am writing an NUnit test that I want run only in the Release

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.