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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:26:02+00:00 2026-05-26T15:26:02+00:00

I usually use Nunit but in my current project I am using MSTest. Now

  • 0

I usually use Nunit but in my current project I am using MSTest. Now I have a test which expects an exception but keeps failing, and I do not have any idea as to why.

Here is a simple example I have used to replicate the problem:

[TestMethod, ExpectedException(typeof(ErrorResponseException))]
        public void should_throw_exception()
        {
            throw new ErrorResponseException();
        }

The ErrorResponseException is a class that just inherits from Exception, that is it, anyone know why this is failing, I would expect it to pass.

  • 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-26T15:26:03+00:00Added an answer on May 26, 2026 at 3:26 pm

    In NUnit, I would avoid ExpectedException and use Assert.Throws (Exception Asserts) instead. It gives you finer-grained control. Otherwise the test will pass if any portion of the test method throws that exception.

    In MSTest, you could get the same level of control with the old-school construct:

    try
    {
        // code that you expect to throw goes here
        Assert.Fail("Expected MyException");
    }
    catch (MyException ex)
    {
        // optionally assert on the message - this can make tests fragile though
    }
    

    With this, there’s no need for the ExpectedException attribute.

    (The concept comes from the book Test-driven Development: A Practical Guide by David Astels.)

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

Sidebar

Related Questions

I usually use .Net but now I'm playing Scala in IntelliJ 10.5.1. It's interesting
I usually use gedit or terminal in which I have a dark setting black
I usually use Netbeans for PHP development, but have recently had to move to
I usually use the Ruby on Rails framework but for this project I need
I usually use NUnit as a UnitTest Framework ,however where I work now they
I usually use simple quotes, but sometime I get very long lines which I
I usually use Visual Studio Team System 2008 Source Control Explorer with TFS, but
I usually use this line to import file from out of the current folder
I usually use sql parameters with queries, but in this case I need to
I usually use expressions like this CommandArgument='<%# Container.DataItemIndex.ToString() %> ' But I could not

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.