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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:16:06+00:00 2026-05-12T21:16:06+00:00

Is there a simple (Attribute-driven) way to have the following test fail on the

  • 0

Is there a simple (Attribute-driven) way to have the following test fail on the message of the exception.

[TestMethod()]
[ExpectedException(typeof(ArgumentException))]
public void ExceptionTestTest()
{
    throw new ArgumentException("BBB");
}

I would Like to have the test pass if the message in the exception is BBB , but fail if it is anything else. I looked at the second parameter of the ExpectedException attribute, but that is only a message to display in the test report if the Exception type is different.

I know I can try {} catch {} the exception an then assert that the message IsEqual to the message, but that feels clunky.

PS. I’m using the built in Unit testing of Visual Studio 2008 (pro)

  • 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-12T21:16:06+00:00Added an answer on May 12, 2026 at 9:16 pm

    The built-in stuff in Visual Studio is poor. Take a look at NUnit. It’s loads more sophisticated, has syntax helpers that make it easier to specific Asserts, can be run as part of your debugging or stand-alone, has a console runner as well as the UI and so on. I’ve been using it for years – it’s the business. The Exception message options give flavour of how sophisticated it is:

    public enum MessageMatch
    {
        /// Expect an exact match
        Exact,  
        /// Expect a message containing the parameter string
        Contains,
        /// Match the regular expression provided as a parameter
        Regex,
        /// Expect a message starting with the parameter string
        StartsWith
    }
    

    Don’t be put off: it is sophisticated but it’s not complicated – it’s very easy to get working.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a simple way to set the text alignment of all cells in
I have implemented in my app the mitigation to CSRF attacks following the informations
I have small number of GUI attribute that i need to save in my
I'm a bit further along in converting some sample test/specs from Watir to Selenium.
I would like to dynamically apply the MEF Export attribute to a type at
I have read posts on passing arrays from and to activities, but I am
I want to sync the Core Data on iPhone with MongoDB on Sinatra server.
I am trying to use AppEngine-MapReduce. I understand how to perform an operation over
I need to display a full screen DirectX window from a Qt app. Although
I've got a checkbox: <td class=checkbox> <input type=checkbox value=100 id=chkbox_100 name=chkbox[] class=chkbox_selector disabled=> </td>

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.