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 618385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:32:23+00:00 2026-05-13T18:32:23+00:00

So I have a method i’m unit testing via MSTests to ensure it throws

  • 0

So I have a method i’m unit testing via MSTests to ensure it throws an exception properly on bad data coming in.

However that method has Debug.Assert so it’s caught while debugging if it happens during an actual test where I’m in debug mode trying to find a bug.

So the unit tests fail at being automatable when run in this way because the Assert statement comes up with Abort, Retry, Ignore. All 3 situations are important:

I’m debugging and looking for a problem, so I want the Debug.Assert to be available.
The code should have the proper guard clause so if it happens in production an exception is thrown.
My unit test should be completely automated and run without manual clicking.

What’s the work around?

  • 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-13T18:32:23+00:00Added an answer on May 13, 2026 at 6:32 pm

    So far when the unit tests are run locally Nicole’s solution didn’t do what I wanted, because I was intentionally passing in values that would trip the Asserts to make sure exceptions are thrown, interferes with running the unit tests automated locally. I suppose it would work if I was willing to accept the [Conditional("DEBUG")] compilation attribute and run the unit tests in release mode. If I want that behavior I can provide a test level(or assembly level) wrapper with the [Conditional("DEBUG")] in the testing assembly, but this one I can utilize from a pre-compiled reusable class library.

    This gets pretty close to what I want, with the additional requirement of calling Trace.Listeners.Clear(); in my test suite.

    /// <summary>
    /// To suppress UI assert messages use:
    /// Trace.Listeners.Clear();
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="assertAgainst"></param>
    /// <param name="condition"></param>
    /// <param name="exception"></param>
    /// <returns></returns>
    public static T Assert<T>(this T assertAgainst, Func<T,bool> condition,Func<Exception> exception)
    {
        var conditionMet = condition(assertAgainst);
        if (Debugger.IsAttached)
            Debug.Assert(conditionMet);
    
            //assertAgainst.Assert(x => x != null, () => new NullReferenceException());
            if (!conditionMet)
                throw exception();
    
        return assertAgainst;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have method in my web service which loads the same mySQL data into
I have method in my BLL that interacts with the database and retrieves data
I have a request(POST or GET), having one variable data (coming from Xcode) now
I have method List<Foo> getFoos () which gets the data from remote server and
Here is a question: I have method digest(byte[] data) . It should be private,
I have method which updating data in database from CSV. csv_text = File.read(#{Rails.root}/db/seed/books.csv) csv
I have method that returns Drawable , and if its Bitmap object is recycled
I have method that returned NSManagedObject and I don't know what kind of NSManagedObject
I have method with two parameters: bool1 and bool2. Both are boolean of course.
I have method that returns module path of given class name def findModulePath(path, className):

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.